欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ssi架构下使用struts2的标签的一个小问题 博客分类: web框架  

程序员文章站 2024-03-07 23:39:45
...


 1 首先说一下web.xml中struts2的Filter配置如下

	
   <filter>
		<filter-name>struts2</filter-name>
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
			<!-- org.apache.struts2.dispatcher.FilterDispatcher-->
		</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>*.action</url-pattern>
	</filter-mapping>



    根目录下index.jsp代码如下

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  
  <%
  String str = "测试文本";
  request.setAttribute("cc",str);
  %>
  
  <body>
    This is my JSP page. <br>
     <form action="login.action">
    	username:<input type="text" name="userDto.username" value="" /><br>
    	password:<input type="text" name="userDto.password" value="" /><br>
    	<input type="submit" name="" value="submit" />
    	
    	<s:property value="cc" />
    </form>
  </body>
</html>


直接请求/index.jsp后发现浏览器报错如下

HTTP Status 500 - The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

 


 

type Exception report

 

message The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

 

description The server encountered an internal error that prevented it from fulfilling this request.

 

exception

org.apache.jasper.JasperException: The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.jshand.sysframework.filter.SessionFilter.doFilter(SessionFilter.java:58)

 

 

 

root cause

The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
	org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
	org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
	org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
	org.apache.jsp.index_jsp._jspx_meth_s_005fproperty_005f0(index_jsp.java:133)
	org.apache.jsp.index_jsp._jspService(index_jsp.java:104)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.jshand.sysframework.filter.SessionFilter.doFilter(SessionFilter.java:58)

 

 

 

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.

 


 

Apache Tomcat/6.0.36

 

 

经分析后发现 如果使用strus2标签,则需要在使用之前当前请求要经过Struts2的核心处理,即Struts2的核心控制类,而我在web.xml中配置Struts2过滤器只配置了<url-pattern>*.action</url-pattern>仅处理了后缀名为action的请求,而直接访问jsp是不会处理的, 顾将此处改成<url-pattern>/*</url-pattern>后问题解决

  • ssi架构下使用struts2的标签的一个小问题
            
    
    博客分类: web框架  
  • 大小: 9.9 KB