默认Action,所有未找到路径显示error.jsp页面。
<default-action-ref name="index"></default-action-ref>
<action name="index"> <result>/error.jsp</result></action>
package com.action;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import org.apache.struts2.util.ServletContextAware;import com.opensymphony.xwork2.ActionSupport;public class HelloWord extends ActionSupport implements ServletRequestAware, ServletResponseAware,ServletContextAware{ public String add(){ return "add"; } public String update(){ return "update"; } @Override public String execute() throws Exception{ System.out.println("执行action"); return SUCCESS; } @Override public void setServletResponse(HttpServletResponse response) { // TODO Auto-generated method stub } @Override public void setServletRequest(HttpServletRequest request) { // TODO Auto-generated method stub } @Override public void setServletContext(ServletContext context) { // TODO Auto-generated method stub }}
struts.xml
/error.jsp /result.jsp /{1}.jsp /{1}.jsp