问题描述
--------------------sturts。xml<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><constantname="struts.action.extension"value="do"/><packagename="aopstruts"namespace="/list"extends="struts-default"><actionname="aopstruts_*"class="org.zym.struts2.strutsParam"method="{1}"><resultname="success">/WEB-INF/page/strutsParam.jsp</result></action><actionname="aopstrut"><result>/index.jsp</result></action></package></struts>----------------WEB.XML<?xmlversion="1.0"encoding="UTF-8"?><web-appid="WebApp_9"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/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>StrutsBlank</display-name><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>------------------packageorg.zym.struts2;publicclassPerson{privateIntegerid;publicIntegergetId(){returnid;}publicvoidsetId(Integerid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}privateStringname;}---------------------------packageorg.zym.struts2;publicclassstrutsParam{privateintid;privateStringname;privatePersonperson;publicPersongetPerson(){returnperson;}publicvoidsetPerson(Personperson){this.person=person;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringreturnadd(){return"success";}}<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><body><formaction="<%=request.getContextPath()%>/list/aopstruts_returnadd.do"method="post">id:<inputtype="text"id="person.id"name="person.id"/><br/>name:<inputtype="text"id="person.name"name="person.name"/></br>submit:<inputtype="submit"value="提交"></form></body></html><%@pagelanguage="java"import="java.util.*"pageEncoding="ISO-8859-1"%><%Stringpath=request.getContextPath();%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"></head><body>ID:${person.id}------;<br/>name:${person.name}-------;</body></html>-----最后得带一个结果就是index.jsp页面提交的值但是在index。jsp页面中id:<inputtype="text"id="person.id"name="person.id"/><br/>name:<inputtype="text"id="person.name"name="person.name"/></br>这里取值只用id时在后端person类中的不到值得,能有那么属性才有值,想了一下不知道为什么,不知道各位大虾有什么间接另外:为什么name="person.id"这样传只在后端能接受到。什么原理。。。就是程序解析步骤是怎么实现的有兴趣的可以详细说明一下呵呵一起提高。。。。。
解决方案
解决方案二:
这个就向常规Form一样,你有见过用标签的ID提交的么。。。其实struts2的前端标签与HTML差别不大
解决方案三:
name="person.id",这样写的Form在提交后,Struts过滤器看到了,用拦截器获取到了参数person.id,往目标Action类上去映射,先找person属性,再找person属性的id属性,把值送到Action类person属性的id属性中,以供后用...
解决方案四:
该回复于2011-04-09 09:25:47被版主删除