The Struts dispatcher cannot be found.
运行后报了这样一个错误,我是个新手想不太明白。网上也找了一些答案,可都不好使。
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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
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:58)
org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:131)
org.apache.jsp.login_jsp._jspService(login_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs.
Apache Tomcat/7.0.64
这是我的代码:
login.jsp
<%@ page language="java" import="java.util.*,zuoye1.*" pageEncoding="UTF-8"%>
<%@ taglib uri ="/struts-tags" prefix ="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
<meta http-equiv ="prama" content = "no-cache">
<meta http-equiv ="cache-control" content ="no-cache">
<meta http-equiv ="keywords" content = "keyword1,keyword2,keyword3">
<meta http-equiv ="description" content = "This is my page">
</head>
<body>
<s:form action="/login" method="post">
<s:label value="系统登录"> </s:label>
<s:textfield name = "username" label ="账号"/>
<s:password name = "password" label = "密码"/>
<s:submit value="登录"/>
</s:form>
</body>
</html>
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>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struct.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Struts PUBLIC
"//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://Struts.apache.org/dtds/Struts-2.0.dtd">
<Struts>
<package name ="default" namespace ="/" extends = "Struts-default">
<action name = "login" class ="zuoye1.LoginAction" method ="execute">
<result name = "success">/welcome.jsp</result>
<result name = "login">/login.jsp</result>
</action>
</package>
<!-- Add package here -->
</Struts>
LoginAction.java
package zuoye1;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getpPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String execute() throws Exception {
if("haha".equals(username) && "hehe".equals(password))
{
return SUCCESS;
}
return LOGIN;
}
}
望解答。