<filter>
<filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>1、配置struts.xml时Action中不配置namespace,默认namespace为 “ ”
struts.xml中
<package name="test" extends="struts-default" >
<action name="init_action" class="com.wei.action.LoginAction" method="init"> <result>/login.jsp</result> </action> </package>
jsp中
<form action="init_action.action" method="post">
用 户 名:<input type="text" name="user" value="" maxlength="20" size="20"><br> 密 码: <input type="password" name="pwd" value="" maxlength="20" size="20"><br> 确认密码:<input type="password" name="pwd" value="" maxlength="20"size="20"> <br> <input type="submit" name="login" value="登录"> </form>2、配置struts.xml时Action中配置namespace=“/test ”
struts.xml中
<package name="test" extends="struts-default" namespace=/test“”>
<action name="init_action" class="com.wei.action.LoginAction" method="init"> <result>/login.jsp</result> </action></package>
jsp中
<form action="test/init_action.action" method="post">
用 户 名:<input type="text" name="user" value="" maxlength="20" size="20"><br> 密 码: <input type="password" name="pwd" value="" maxlength="20" size="20"><br> 确认密码:<input type="password" name="pwd" value="" maxlength="20"size="20"> <br> <input type="submit" name="login" value="登录"></form>欢迎交流,评论!