在使用struts2时,我该如何页面上用户输入的值传入到action中验证呢?我的action是没有继承actionSupport
能不能给我写一个最简单的jsp各属性该怎么写(name,class。。。之类)实在不知道各个属性代表的是什么值,我现在在ie中输入.action无法访问到网页,输入jsp...
能不能给我写一个最简单的jsp各属性该怎么写(name,class。。。之类)实在不知道各个属性代表的是什么值,我现在在ie中输入.action无法访问到网页,输入jsp才可以,怎么解决。谢谢大虾
展开
1个回答
展开全部
jsp:
<form action="test.action">
<input type="text" name="name" />
<input type="submit" />
</form>
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="test" class="com.test.action.testAction">
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
testAction:
public class testAction extends ActionSupport {
private String name;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public String execute() throws Exception {
System.out.println(name);
return SUCCESS;
}
}
<form action="test.action">
<input type="text" name="name" />
<input type="submit" />
</form>
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="test" class="com.test.action.testAction">
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
testAction:
public class testAction extends ActionSupport {
private String name;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public String execute() throws Exception {
System.out.println(name);
return SUCCESS;
}
}
追问
web.xml要如何配置呢?
追答
test
org.apache.struts2.dispatcher.FilterDispatcher
test
/*
//这个可以不要
org.springframework.web.context.ContextLoaderListener
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询