这是我的第一个struts2程序,从网上视频看来的,但老是出现404报错,求救啊...下面是代码: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.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<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>
<package name="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result>/result.jsp</result>
</action>
</package>
</struts>
login.jsp:<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>My JSP 'login.jsp' starting page</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><blockquote><br></blockquote><form action="login.action" method="post">
    username:<input type="text" name="username"/><br/>
    password:<input type="password" name="password"/><br/>
    <input type="submit" value="submit"/>
    </form>
  </body>
</html>
result.jsp:<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>My JSP 'result.jsp' starting page</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>
    username:${requestScope.username}<br/>
    password:${requestScope.password}
  </body>
</html>

解决方案 »

  1.   

    帖 访问地址、action中方法 
      

  2.   

    strut.xml中的 
    <result name="action中的返回结果">/result.jsp</result>
    你试下看
      

  3.   

    在配置文件中你定义了包名:struts2
    <package name="struts2" extends="struts-default">
    那么在form中也必须跟上包名。可以用struts2提供的标签
    <s:form name="login" namespace="struts2" Method="post">
      

  4.   

    解决办法: 关闭服务器——>将web.xml 移动至另外一个文件夹,然后又将其移动到WEB_INF文件夹下——>重启服务器。
      

  5.   

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

  6.   


    不写默认的就是namespace=“/”
      

  7.   

    可能的错误原因是你原来的项目起了一个名字,然后呢,你把项目改名字了,可是在服务器端的访问路径还是买有改过来。具体就看:项目右键-->Properties-->MyEclipse-->Web-->Web Context-root 一项中是否是你访问的项目名字了!如果不是就改过来。
      

  8.   

    报404错误肯定是文件找不到,这个不用怀疑.你先在action的execute方法中下个断点,看看能不进入到这个action,能进来就好办.如果能进来就去<result>标签体内写上jsp页面的绝对路径,再试下.struts2默认是转发的,你在这写相对路径的话就要求result.jsp在WebRoot目录下面,你仔细看下,如果可以的话用MyEclipse打开这个程序,把左侧的项目文件结构截个图给我看下.