struts1的配置文件
程序员文章站
2022-04-08 18:42:57
...
1.配置struts1时,需要在web.xml中配置相关信息:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 出错页面定义 --> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/common/500.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/common/500.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/common/404.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/common/403.jsp</location> </error-page> <resource-ref> <description>DB2 Connection</description> <res-ref-name>jdbc/DW</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <!-- <resource-ref> --> <!-- <description>DB2 Connection</description> --> <!-- <res-ref-name>jdbc/ZJ_DC</res-ref-name> --> <!-- <res-type>javax.sql.DataSource</res-type> --> <!-- <res-auth>Container</res-auth> --> <!-- </resource-ref>--> </web-app>
2.此外,struts.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans> <form-bean name="UploadWbgyActionForm" type="org.xcx.struts.form.UploadWbgyActionForm"></form-bean> <form-bean name="UploadNbgwActionForm" type="org.xcx.struts.form.UploadNbgwActionForm"></form-bean> </form-beans> <global-exceptions /> <global-forwards > <forward name="error" path="/error.jsp"></forward> <forward name="json" path="/json.jsp"></forward> </global-forwards> <action-mappings > <action parameter="method" path="/wbgy" type="org.xcx.struts.action.GWXX_WBGYAction" name="UploadWbgyActionForm"> <forward name="error" path="/error.jsp"></forward> <forward name="insertWbgy" path="/jsp/wbgy/insertWbgy.jsp"></forward> <forward name="success" path="/success.jsp"></forward> <forward name="WBGYList" path="/jsp/wbgy/AllWbgy.jsp"></forward> <forward name="WbgwDetail" path="/jsp/wbgy/WbgyDetail.jsp"></forward> <forward name="PreAllWbgy" path="/jsp/wbgy/PreAllWbgy.jsp"></forward> <forward name="PreAllWbgyTONGJI" path="/jsp/wbgy/PreAllWbgyTONGJI.jsp"></forward> </action> <action parameter="method" path="/login" type="org.xcx.struts.action.LoginAction"> <forward name="error" path="/error.jsp"></forward> <forward name="indexLoginSuccess" path="/indexLoginSuccess.jsp"></forward> <forward name="index" path="/index.jsp"></forward> <forward name="login" path="/login.jsp"></forward> </action> </action-mappings> <controller processorClass="org.xcx.struts.action.Encoding" maxFileSize="-1"></controller> <message-resources parameter="org.xcx.struts.action.ApplicationResources" /> </struts-config>
3.其中的Action继承的是DispatchAction,当访问时,url为contentPath + wbgy.do?method=getAllWBGYXX。以下是action中的一个method对应的方法:
public ActionForward getAllWBGYXX(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { List<GWXX_WBGY> WBGYList = new ArrayList<GWXX_WBGY>(); HttpSession session = request.getSession(); FgyjdaRsQxYh user = (FgyjdaRsQxYh)session.getAttribute("user"); int qx = (Integer)session.getAttribute("qx"); String param =""; if(qx==3){//本人 param =" where LRRZYBM='"+user.getZybm()+"'"; }else if(qx==6){//本部门 param =" where LRRBMDM="+user.getBmdm()+" and fydm="+user.getFydm(); } WBGYList = wbgyServer.getAllWBGY(param); if(XXX){ request.setAttribute("WBGYList", WBGYList); return mapping.findForward("WBGYList"); }else{ return mapping.findForward("error"); } }
4.需要添加相应的方法只需要增加相应的method方法,转发url的name,根据name重新跳转页面:
public ActionForward getAllWBGYXX(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){ //业务处理 return mapping.findForward("xxx"); }
5.相关跳转的信息在struts.xml中配置。
下一篇: Qt Creator的下载和安装
推荐阅读
-
【MySQL】only_full_group_by导致的group by错误解决方案。
-
图象函数中的中文显示_PHP
-
出现“this is incompatible with sql_mode=only_full_group_by“问题的解决方案
-
【UWP】自带的EntityFrameWorkCore数据库(新数据库)的配置教程
-
Zend Framework中的简单工厂模式 图文_PHP
-
【剑指 Offer 53 - II】0~n-1中缺失的数字
-
MySql5.7版本问题sql_mode=only_full_group_by的完美解决方案
-
记录Mac上安装homebrew以及python3的过程
-
Docker之MySql5.7中only_full_group_by的问题解决
-
关于html、asp、php模板引擎、aspnet mvc、REST的一点思考