struts2新手求助,使用myeclipse8.5导入struts2.1后使用标签库报错

时间:2022-03-09 09:36:00
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
  <head>
  </head>
  
  <body>
<s:form name="converter">
</s:form>
  </body>
</html>

报错内容
console报错:
严重: Servlet.service() for servlet jsp threw exception
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]
JSP页面报错:
type Exception report

message 

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

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /convert.jsp at line 9

6:   </head>
7:   
8:   <body>
9:  <s:form name="converter">
10:  </s:form>
11:   </body>
12: </html>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
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)


我一步步跟着教程做的了~

7 个解决方案

#1


myeclipse直接导入的有几个包冲突,去掉了没?

#2


配置 WEB.XML是否正常啊

#3


你把你的配置发下。
可能是过滤器配置错误。

#4


引用 1 楼 yodlove 的回复:
myeclipse直接导入的有几个包冲突,去掉了没?


哪几个包冲突呀?我是新手~刚接触struts2没几天~

#5


引用 3 楼 closewbq 的回复:
你把你的配置发下。
可能是过滤器配置错误。


<?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">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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>
   <url-pattern>*.action</url-pattern>
  </filter-mapping></web-app>

麻烦帮我看一下~谢谢~

#6


引用 3 楼 closewbq 的回复:
你把你的配置发下。
可能是过滤器配置错误。


我注册了taglib后还是报错。。。

<?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">
<jsp-config>
<taglib>
<taglib-uri>struts-tags</taglib-uri>
<taglib-location>/WEB-INF/struts2-core-2.1.8.1.jar</taglib-location>
</taglib>
</jsp-config> 
  <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>
   <url-pattern>*.action</url-pattern>
  </filter-mapping>
  </web-app>

#7


应该是创建struts2的时候  只导入了core核心包...没导入标签库吧

#1


myeclipse直接导入的有几个包冲突,去掉了没?

#2


配置 WEB.XML是否正常啊

#3


你把你的配置发下。
可能是过滤器配置错误。

#4


引用 1 楼 yodlove 的回复:
myeclipse直接导入的有几个包冲突,去掉了没?


哪几个包冲突呀?我是新手~刚接触struts2没几天~

#5


引用 3 楼 closewbq 的回复:
你把你的配置发下。
可能是过滤器配置错误。


<?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">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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>
   <url-pattern>*.action</url-pattern>
  </filter-mapping></web-app>

麻烦帮我看一下~谢谢~

#6


引用 3 楼 closewbq 的回复:
你把你的配置发下。
可能是过滤器配置错误。


我注册了taglib后还是报错。。。

<?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">
<jsp-config>
<taglib>
<taglib-uri>struts-tags</taglib-uri>
<taglib-location>/WEB-INF/struts2-core-2.1.8.1.jar</taglib-location>
</taglib>
</jsp-config> 
  <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>
   <url-pattern>*.action</url-pattern>
  </filter-mapping>
  </web-app>

#7


应该是创建struts2的时候  只导入了core核心包...没导入标签库吧