新建个项目,启动后报404和500,求大神解答

秋名山的奥迪双钻 2017-12-12 11:19:57
文件结构:(图传不上去就直接写了)
src:struts.xml / struts.properties / 包com.action里有个UserAction.java
WebContent: index.jsp / hello.jsp WEB-INF里lib文件夹和web.xml, struts需要的包都导在lib里了

现在如果web.xml放在WEB-INF里,项目启动的话就404,放在src下就能启动;
还有能启动的话,会报500的错
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]

请求大神解惑(就算不会水一下也行啊,之前的帖子没人回都没法结贴),下面贴代码
index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index</title>
</head>
<body>
<s:a action="hello">hello</s:a>
</body>
</html>


hello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>error</title>
</head>
<body>
<center>
${applicationScope.name }<br />
${sessionScope.name }<br />
${requestScope.name}<br />
</center>
</body>
</html>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<filter>
<!-- Filter名称 -->
<filter-name>struts2</filter-name>
<!-- Filter入口 -->
<filter-class>org.apache.struts2.dispathcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<!-- Filter名称 -->
<filter-name>struts2</filter-name>
<!-- 截获的所有URL -->
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<!-- 开始页面 -->
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>


struts.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.xml文件的根元素 -->
<struts>
<!-- 配置包,包名为default,该包继承了struts 2框架的默认包struts-default -->
<package name="default" namespace="/" extends="struts-default">
<!-- 定义名为hello的Action,该Action的处理类为com.action.UserAction,并映射到hello.jsp的页面 -->
<action name="hello" class="com.action.UserAction">
<result name="hello">/hello.jsp</result>
</action>
</package>
</struts>


struts.properties

<struts.i18n.encoding value="UTF-8"/>


UserAction.java

package com.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
private static final long serialVersionUID = 1L;

public String execute() throws Exception{
ActionContext context = ActionContext.getContext();
context.put("name", "request:tom");
context.getApplication().put("name", "application:tom");
context.getSession().put("name", "session:tom");
return "hello";
}
}


...全文
329 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 ai977313677 的回复:
[quote=引用 6 楼 m0_37518156 的回复:] [quote=引用 4 楼 ai977313677 的回复:] 应该是在jsp页面使用struct2标签时,页面没有使用action跳转 web.xml在里面添加

<filter-mapping>  
    <filter-name>struts2</filter-name>  
    <url-pattern>*.jsp</url-pattern>  
</filter-mapping>
 
试过了,没用,还是报500[/quote] 仔细看了一下,你的配置是没有问题的,你现在需要把web.xml放到web-inf文件夹下,然后启动(你的tomcat或者其他服务器环境应该是配置好的),现在如果出现404,你看一下你的浏览器地址栏,如果是只是localhost:8080,你要改一下地址栏(当然eclipse是有自带的浏览器,自带的浏览器应该是直接打开index.jsp),改成localhost:8080/项目名/action名,应该就没有问题了。[/quote] 今天莫名其妙好用了,不过还是谢谢你的回答
  • 打赏
  • 举报
回复
引用 4 楼 ai977313677 的回复:
应该是在jsp页面使用struct2标签时,页面没有使用action跳转 web.xml在里面添加

<filter-mapping>  
    <filter-name>struts2</filter-name>  
    <url-pattern>*.jsp</url-pattern>  
</filter-mapping>
 
试过了,没用,还是报500
Cherry_Yas 2017-12-12
  • 打赏
  • 举报
回复
顶一哈,新人看不懂
  • 打赏
  • 举报
回复
应该是在jsp页面使用struct2标签时,页面没有使用action跳转 web.xml在里面添加

<filter-mapping>  
    <filter-name>struts2</filter-name>  
    <url-pattern>*.jsp</url-pattern>  
</filter-mapping>
 
  • 打赏
  • 举报
回复
自顶,来人啊!!!
  • 打赏
  • 举报
回复
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:555) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 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: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_005fa_005f0(index_jsp.java:163) org.apache.jsp.index_jsp._jspService(index_jsp.java:129) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 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/8.0.36 logs.
  • 打赏
  • 举报
回复
就这点分了,希望大神别介意,求解答,我顶!
  • 打赏
  • 举报
回复
引用 6 楼 m0_37518156 的回复:
[quote=引用 4 楼 ai977313677 的回复:] 应该是在jsp页面使用struct2标签时,页面没有使用action跳转 web.xml在里面添加

<filter-mapping>  
    <filter-name>struts2</filter-name>  
    <url-pattern>*.jsp</url-pattern>  
</filter-mapping>
 
试过了,没用,还是报500[/quote] 仔细看了一下,你的配置是没有问题的,你现在需要把web.xml放到web-inf文件夹下,然后启动(你的tomcat或者其他服务器环境应该是配置好的),现在如果出现404,你看一下你的浏览器地址栏,如果是只是localhost:8080,你要改一下地址栏(当然eclipse是有自带的浏览器,自带的浏览器应该是直接打开index.jsp),改成localhost:8080/项目名/action名,应该就没有问题了。

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧