strust1配置
程序员文章站
2022-04-08 19:56:35
...
1.在web.xml中加入struts1的过滤器,使web项目支持struts1
<servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <!-- 指定struts配置文件struts-config.xml的路径 --> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
2.创建stauts-config.xml文件,配置action
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <action-mappings> <!-- path:访问该Action的路径 type:该Action的类 --> <action path="/toLogin" type="com.cong.LoginAction"> <!-- name:相当于struts2中result的名字 path:需要转发到的路径 redirect:是否使用重定向 --> <forward name="success" path="/WEB-INF/jsp/login/somepage1.jsp"/> </action> <action path="/todo" type="com.cong.LoginAction"> <forward name="success" path="/WEB-INF/jsp/login/somepage2.jsp" /> </action> </action-mappings> </struts-config>
3.添加Action类LoginAction.java
public class LoginAction extends Action { @Override // Action 处理请求 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("success"); // return super.execute(mapping, form, request, response); } }
4.在jsp页面使用超链接跳转
<a href="todo.do">goto</a>
上一篇: Abp添加菜单
下一篇: 深入理解this关键字