web.xml文件
<?xml version="1.0" encoding="GB2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<!--过滤器名字 -->
<filter-name>struts2</filter-name>
<!-- 过滤器支持的struts2类 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.action</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
原因:如果想要在jsp文件中,采用 struts的tag,那么必须通过web.xml所配置的过滤器访问文件,否则会有异常,即 之前所出现的异常。
解决方案:
方案一:
采用对应的action来访问
方案二:
将web.xml 的过滤器,从 *.action 修改为: /*
或者将为struts2,添加一个新的过滤类型
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
方案三:
修改SayHello.jsp 文件,不使用 struts 的标签。
更改后的web.xml
<?xml version="1.0" encoding="GB2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<!--过滤器名字 -->
<filter-name>struts2</filter-name>
<!-- 过滤器支持的struts2类 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="GB2312"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<!--过滤器名字 -->
<filter-name>struts2</filter-name>
<!-- 过滤器支持的struts2类 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<!--过滤器拦截名字 -->
<filter-name>struts2</filter-name>
<!--过滤器拦截文件路径名字 -->
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>