今天鼓捣了一天的struts2,终于给跑出来了。希望对以后还能有帮助。
首先是web.xml的文件
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <!-- 2.3.1.2版本的 -->
<!-- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class> <!-- 2.1.6版本的 --> -->
</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>
其次是 struts.xml 的配置文件 路径:这个一定要放到src下
<!-- 开启使用开发模式,详细错误提示 -->
<constant name="struts.devMode" value="false" />
<!-- action配置 -->
<package name="default" extends="struts-default"
namespace="/test">
<action name="hello" class="ssh.Hello">
<result name="success">/hello.jsp</result>
</action>
</package>
下面是jsp的
<!-- <%=path%>/命名空间/+action别名.action -->
<form action="<%=path%>/test/hello.action" method="post">
<input type="text" name="test" id="test" value="" />
<input type="submit" value="提交" />
</form>
<!-- 命名空间/+action别名.action -->
<s:form action="/test/hello.action" method="post">
<s:submit value="提交"></s:submit>
</s:form>
上面配置全了就可以运行了,如果出现找不到action的异常,看你的struts.xml路径是不是正确,你的jsp命名空间是不是和配置文件一致。