public class UserAction extends ActionSupport implements ModelDriven<Object>, Preparable{
加上
@Namespace("/fanice/user")
@Results( { @Result(name = "success", location = "index.jsp"),
@Result(name = "error", location = "index.jsp") })
@Action("oss")
public class UserAction extends ActionSupport implements ModelDriven<Object>, Preparable{
加上
@Namespace("/fanice/user")
@Results( { @Result(name = "success", location = "index.jsp"),
@Result(name = "error", location = "index.jsp") })
@Action("oss")
public class UserAction extends ActionSupport implements ModelDriven<Object>, Preparable{
package com.example.actions;import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;public class HelloWorld extends ActionSupport {
@Action(value="/different/url",
results={@Result(name="success", type="httpheader", params={"status", "500", "errorMessage", "Internal Error"})}
)
public String execute() {
return SUCCESS;
} @Action("/another/url")
public String doSomething() {
return SUCCESS;
}
}
官网山看到的一段代码
修改为
@Namespace("/fanice/user")
@Results( { @Result(name = "success", location = "/index.jsp"),
@Result(name = "error", location = "/index.jsp") })
@Action("oss")
public class UserAction extends ActionSupport implements ModelDriven<Object>, Preparable{
后台也应该有输出啊可是我的后台没有输出
@Namespace("/fanice/user")
@Results( { @Result(name = "success", location = "/WEB-INF/page/fanice/user/index.jsp"),
@Result(name = "error", location = "/WEB-INF/page/fanice/user/index.jsp") }) 试试
debug 进不去,没挂上。哎,悲剧啊为什么这里有个小点 ,问题会不会出在这里?
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>MyCommon</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- 配置spring的监听器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- Character Encoding Filter -->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<!-- 强制进行转码 -->
<param-value>true</param-value>
</init-param>
</filter>
<!-- Open Session In View Filter -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 延长action中属性的生命周期, -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<!-- Struts2 Filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,classpath*:struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Spring Listener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Spring提供的一个用来防止内存泄露的监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener></web-app>
@Action(value="oss",results={ @Result(name = "success", location = "index.jsp"),
@Result(name = "error", location = "index.jsp") })
这里面试试
@Results( { @Result(name = "success", location = "/index.jsp"),
@Result(name = "error", location = "/index.jsp") })
@Action("oss")
public class RegistAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L; public String execute() {
System.out.println("Welcome to Annotation");
return SUCCESS;
}
}
struts.xml 为空
web.xml<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>struts2</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.zhangqi.action.RegistAction</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
web.xml中需要扫描配置action的包,楼主的里面配一堆spring的东东,不太熟悉
然后就是 webRoot下面的index.jsp了
可以成功访问。
建议楼主将web.xml简化下,先让程序跑起来,再添加监听等等。