Mr.Daru 2017-05-05 08:55 采纳率: 76.5%
浏览 1182
已采纳

struts2 注解开发问题!!!!!!!!

使用注解的,之前好像还没问题来着...现在不知道问题出在哪里了

action

```package com.sg.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.sg.service.ArtileService;
@Controller
@Namespace("")
@Action(value="test" ,results={
@Result (name="success" ,location="./jsp/top.jsp"),
@Result (name="fail" ,location="./jsp/top.jsp")
})

public class aritcleAction extends ActionSupport{
@Resource
ArtileService as;

public String execute(){
    System.out.println("aaaa");
    return"fail";

}

}


jsp

```<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>

  <body>
    <s:form action="test">
    <s:submit></s:submit>
    </s:form>

    </body>
</html>


struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>  

    <!-- 请求参数的编码方式-->

    <constant name="struts.i18n.encoding" value="UTF-8"/>

    <!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开-->

    <constant name="struts.action.extension" value="action,do,html"/>

    <!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开  -->

    <constant name="struts.configuration.xml.reload" value="true"/>

    <!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开  -->

    <constant name="struts.devMode" value="true"/>  

    <!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭  -->

    <constant name="struts.serve.static.browserCache" value="false" />

    <!-- 指定由spring负责action对象的创建   

    <constant name="struts.objectFactory" value="spring" />

    -->

    <!-- 是否开启动态方法调用-->

    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>

</struts>

1.页面提交的时候访问路径http://localhost:8080/sg/jsp/test,后面的.action怎么不见了?
2.http://localhost:8080/sg/jsp/test.action访问就下面的报错了
There is no Action mapped for namespace /jsp and action name test. - [unknown location]

namespace("")默认命名空间好像就不会因为命名空间的问题而找不到了吧,namespace("/jsp")试了,不行

所以是这个注解基本没有生效的意思吗?
问题出在哪里呢........??

补充一个web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


    <!-- 加载spring配置文件 -->
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </context-param>

    <listener>
     <listener-class>
         org.springframework.web.context.ContextLoaderListener
     </listener-class>
 </listener>
 <!-- struts2 的配置 -->
 <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <display-name></display-name> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

  • 写回答

2条回答 默认 最新

  • kingbaron 2017-05-05 09:12
    关注

    劝你赶紧弃坑,转投SpringMVC大法好。2017年3月7日,Struts框架再次曝出了“高危”漏洞(CNNVD-201703-152 ,CVE-2017-5638),该漏洞存在于Struts框架多个版本。这个框架基本上没什么前途了,弃坑要趁早!!!!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置