Topic: Struts-config.xml看不懂,请高手指点一二 |
Print this page |
1.Struts-config.xml看不懂,请高手指点一二 | Copy to clipboard |
Posted by: AaronTong Posted on: 2007-12-07 14:57 <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE Struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/Struts/dtds/Struts-config_1_1.dtd";> <!-- This is the Struts configuration file for the example application, using the proposed new syntax. --> <Struts-config> <!-- ========== Form Bean Definitions =================================== --> <!-- FormBean是Struts的一个概念,本质是JavaBean,用来自动存储页面表单中各个域的值,并在适当的时候回填表单域,不需要象传统那样request.getParameter("fieldName");,常被action-mappings中的action 使用 --> <form-beans> <!-- 稍后我们会新增一个GetparameterForm类,用来存储用户信息 --> <form-bean name="GetParameterForm" type="beans.GetParameterForm"/> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <!--这里存放整个系统都可以使用的全局转向中转(Forward)地址 --> <!-- 一般情况下,一个Action处理完毕后,会转发到一个JSP页面进行显示。这也是JSP中的MVC的实现的要点。--> <global-forwards> <!--failed.do和success.do将被当成servlet请求,到action-mappings中寻找对应的action处理。--> <forward name="success" path="/success.do"/> <forward name="fail" path="/fail.do"/> </global-forwards> <!-- ========== Action Mapping Definitions ============================== --> <!--web.xml中后缀为.do的请求被转到这里处理。这里相当于Struts的Model部分,Model部分是Struts中比较灵活的地方。--> <action-mappings> <!--处理showinput.do的请求,使用的FormBean是GetparameterForm,既beans.GetParameterForm类,当处理过程发生错误时将返回index.jsp--> <action path="/showinput" type="beans.ShowAction" name="GetParameterForm" scope="request" input="/index.jsp" /> <action path="/success" forward="/success.jsp"/> <action path="/fail" forward="/error.jsp" /> </action-mappings> </Struts-config> web.xml如下: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <display-name>Struts AddressBook Sample Applications</display-name> <servlet> <servlet-name>beans.GetParameterForm</servlet-name> <servlet-class>beans.GetParameterForm</servlet-class> </servlet> <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> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <url-pattern>/beans/GetParameterForm.class</url-pattern> <servlet-name>beans.GetParameterForm</servlet-name> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> index.jsp如下: <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.util.*,java.sql.*,java.text.*,java.io.*"%> <html> <form name="form1" method="post" action="showinput.do"> 输入success将返回到"success"页面,否则返回到"fail"页面<br><br> input:<input type="text" name="valu"> <input type="submit" value="submit"> </form> <br> <a href="success.do">success</a><br> <a href="fail.do">fail</a> </html> 不管是输入点提交,还是直接点链接都提示 The requested resource (Servlet action is not available) is not available |
2.Re:Struts-config.xml看不懂,请高手指点一二 [Re: AaronTong] | Copy to clipboard |
Posted by: AaronTong Posted on: 2007-12-08 14:01 人气怎么这么差啊,几天前发的帖,没人来也沉不下去..... |
3.Re:Struts-config.xml看不懂,请高手指点一二 [Re: AaronTong] | Copy to clipboard |
Posted by: windy Posted on: 2007-12-17 10:24 1.<action path="/showinput" type="beans.ShowAction" name="GetParameterForm" scope="request" input="/index.jsp" /> 改为<action path="/showinput" type="beans.ShowAction" name="GetParameterForm" attribute="GetParameterForm" scope="request" input="/index.jsp" /> 2. <form name="form1" method="post" action="showinput.do"> 改为<form method="post" action="showinput.do"> 3. 看看Struts的包都导进项目了吗 |
4.Re:Struts-config.xml看不懂,请高手指点一二 [Re: AaronTong] | Copy to clipboard |
Posted by: spbeyond Posted on: 2008-03-25 16:35 <action-mappings> <action attribute="GetParameterForm" path="/showinput" type="beans.ShowAction" scope="request" input="/index.jsp" /> <action path="/success" forward="/success.jsp"/> <action path="/fail" forward="/error.jsp" /> </action-mappings> action应该这样写!还有就是注意你jsp的文件位置,否则出现找不到文件错误! <form name="form1" method="post" action="/showinput.do">改为! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |