刚搭struts2例子 启动成功 访问不了
配置struts.xml <constant name="struts.i18n.encoding" value="utf-8" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.reload" value="true" />
<package name="struts2" extends="struts-default" namespace="/">
<action name="*" class="com.s2sh.test.action.UserAction" method="{1}">
<result name="success">success.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
UserAction:
public class UserAction extends ActionSupport{
public String add(){
System.out.println("UserAction.add()");
return "success";
}
}
web.xml
<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>
<servlet-name>/*</servlet-name>
</filter-mapping>
访问地址:http://localhost:8080/s2sh_test/add.action 一直都是访问到404
------解决方案--------------------<servlet-name>/*</servlet-name> 这个地方写错了, 改为url-pattern
------解决方案--------------------改成如下:
<url-pattern>/*</url-pattern>