日期:2014-05-17  浏览次数:20663 次

Struts2如何通过过滤器防止直接访问jsp页面
有没有大神有详细点的例子,包括如何配置?
struts2有对过滤器的支持吗?或者只需要配置web.xml就可以?
求详细点的教程或例子。。
还有,如果是直接放在webinf里,又该如何写action呢?为什么说不好维护?
------解决方案--------------------
web.xml配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<filter>
<filter-name>myStruts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myStruts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>



struts.xml配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="mystruts" extends = "struts-default">
<action name="helloWorld" class="action.HelloWorld">
<result name="success">
/WEB-INF/jsp/helloWorld.jsp
</result>
</action>
</package>
</struts>



这是我写struts程序的两个配置文件。