struts2中jsp传递参数接受不到
写了个struts2测试程序action无法接受表单传递的参数Struts.xml<struts><constantname="struts.i18n.encoding"...
写了个struts2测试程序 action无法接受表单传递的参数
Struts.xml
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.action.extension" value="action" />
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="do,action" />
<package name="default" namespace="/" extends="struts-default">
<action name="testAction" class="com.lbt.action.TestAction">
<result name="success">MyJsp.jsp</result>
</action>
</package>
</struts>
--------------------
web.xml
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
----------------------
index.jsp
<form action="testAction.action">
<input type="submit" value="Submit">
<input type="text" value="中国" />
</form>
(或者:
<form action="testAction.action?text='汉字'">
<input type="submit" value="Submit">
</form>
)
---------------------
action class
public class TestAction extends ActionSupport{
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String execute(){
System.out.println(text);
return "success";
}
}
本来是想测试中文乱码的 现在连值都传不过来啊
求解 展开
Struts.xml
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.action.extension" value="action" />
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.configuration.xml.reload" value="true" />
<constant name="struts.devMode" value="true" />
<constant name="struts.action.extension" value="do,action" />
<package name="default" namespace="/" extends="struts-default">
<action name="testAction" class="com.lbt.action.TestAction">
<result name="success">MyJsp.jsp</result>
</action>
</package>
</struts>
--------------------
web.xml
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
----------------------
index.jsp
<form action="testAction.action">
<input type="submit" value="Submit">
<input type="text" value="中国" />
</form>
(或者:
<form action="testAction.action?text='汉字'">
<input type="submit" value="Submit">
</form>
)
---------------------
action class
public class TestAction extends ActionSupport{
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String execute(){
System.out.println(text);
return "success";
}
}
本来是想测试中文乱码的 现在连值都传不过来啊
求解 展开
1个回答
展开全部
<form action="testAction.action">
<input type="submit" value="Submit">
<input type="text" value="中国" />//这里要加个name属性 name='text' 是按照name来取值的
</form>
(或者:
<form action="testAction.action?text='汉字'">//这里。。直接testAction.action?text=汉字 就行了。不要加单引号
<input type="submit" value="Submit">
还有问题HI我哈
</form>
<input type="submit" value="Submit">
<input type="text" value="中国" />//这里要加个name属性 name='text' 是按照name来取值的
</form>
(或者:
<form action="testAction.action?text='汉字'">//这里。。直接testAction.action?text=汉字 就行了。不要加单引号
<input type="submit" value="Submit">
还有问题HI我哈
</form>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询