首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts2初学 老是出现HTTP 404 加到80分了, 希望来人帮忙看上

2013-01-12 
struts2初学老是出现HTTP 404加到80分了, 希望来人帮忙看下本帖最后由 wdzwb 于 2013-01-09 11:22:44 编辑

struts2初学 老是出现HTTP 404 加到80分了, 希望来人帮忙看下
本帖最后由 wdzwb 于 2013-01-09 11:22:44 编辑 struts

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<!-- 
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>

        <action name="index">
            <result type="redirectAction">
                <param name="actionName">HelloWorld</param>
                <param name="namespace">/example</param>
            </result>
        </action>
    </package>

    <include file="example.xml"/>
  
   --> 

 <package name="default" namespace="/" extends="struts-default">

         <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>
 
        <action name="hello">
            <result>
/Hello.jsp
            </result>
        </action>
    </package>

    <!-- Add packages here -->
</struts>

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">
  <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>/*</url-pattern>
    </filter-mapping>
</web-app>


Hello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>hello Struts2</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
    Hello Struts2. <br>
  </body>
</html>


老是出现type Status report

message /Struts2_0100_Introduciton/Hello.jsp

description The requested resource is not available.

到底是哪里出错了,struts用的2.341,Myeclipse8.5
[解决办法]
404,很明显,路径不存在
你看看
message /Struts2_0100_Introduciton/Hello.jsp
这个页面在么?
注意大小写。
hello.jsp才对。
注意struts跳转的时候原有的文件路径。
[解决办法]
引用:
404,很明显,路径不存在
你看看
message /Struts2_0100_Introduciton/Hello.jsp
这个页面在么?
注意大小写。
hello.jsp才对。
注意struts跳转的时候原有的文件路径。

+1
[解决办法]
引用:
我也知道这提示就是路径不对,但是我输入的确实是检查n遍了,
http://localhost:8080/Struts2_0100_Introduciton然后
http://localhost:8080/Struts2_0100_Introduciton/hello
http://localhost:8080/Struts2_0100_Introduciton/he……

你截个图我看下,就是jsp放在webROOT下的那个图片。我感觉除非你设置了过滤器或者拦截器给过滤了,要不一般不会出现这样的情况。

[解决办法]
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>


过滤器改为这个。struts.xml里面配置的跳转试图是Hello.jsp,你就要建Hello.jsp文件。
[解决办法]

下面这个是运行页面情况
struts2初学  老是出现HTTP 404    加到80分了, 希望来人帮忙看上
 其他的都是一样的  struts.xml有区别 我的只是头部不同..

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

你认真检查哈你的代码呢..
[解决办法]
亲  我想说  你的核心包添加了吗? 我才发现我们的架构不同!
[解决办法]
亲重建个项目按照视频重新配置struts2,

热点排行