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

初学者初学Struts2被无限404蹂躏两夜!求拯救

2012-09-18 
菜鸟初学Struts2被无限404蹂躏两夜!求拯救初学Struts2 被无限404折腾两夜了 求拯救更希望有人能教教我怎么

菜鸟初学Struts2被无限404蹂躏两夜!求拯救
初学Struts2 被无限404折腾两夜了 求拯救
更希望有人能教教我怎么追踪解决这种问题 给满100分 希望有人肯指教
情况是访问任何页面都是404
去掉web.xml flicker元素正常

环境:eclipse for javaee 
  tomcat 7.0
  struts 2.3.4

web.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Struts2Dome</display-name>
  <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>


struts.xml配置:
<?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.custom.il8n.resources" value="mess"></constant>
<constant name="struts.il8n.encoding" value="UTF-8"></constant> -->
<package name="liu" extends = "struts-default">
<action name = "login" class = "liu.LoginAction">
<result name = "input">/login.jsp</result>
<result name = "error">/error.jsp</result>
<result name = "succeed">/welcome.jsp</result>
</action>
</package>
</struts>


login.jsp:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
  <%@ taglib prefix = "s" uri = "/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>dsdds</title>
</head>
<body>
<form action = "login" method = "post">
<%-- <textfield name = "username" key = "username" />
<textfield name = "password" key = "password" />
<submit key = "login" /> --%>
</form>
</body>
</html>


LoginAction.java :
package liu;

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

public class LoginAction extends ActionSupport{
private String username;
private String password;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

public String execute() throws Exception 
{
if(getUsername().equals("liu") && getPassword().equals("liu"))
{
ActionContext.getContext().getSession().put("user", getUsername());


return "succeed";
}
else 
{
return "error";
}
}
}

文档结构: 
src
  struts.xml
  liu
  ----LoginAction.java
WebContent
  login.jsp
  error.jsp
  welcome.jsp
  web-INF
  ----web.xml
  ----classes
  ----lib
  
  



[解决办法]
404 的问题解决方式 、
1、 首先查看自己的请求发送到Action中没有
2、 看execute()方法执行没有
3、 执行后返回的String是一个url 在struts.xml
查看你的String对应的result是否正确
[解决办法]
public String execute() throws Exception 
{
System.out.println("方法开始执行");
if(getUsername().equals("liu") && getPassword().equals("liu"))
{
ActionContext.getContext().getSession().put("user", getUsername());
System.out.println("方法执行结束");
return "succeed";
}
else 
{
return "error";
}
}
}

楼主加两条打印语句,然后服务启动看后台有没有打印出来,如果两个都打印出来了,说明方法没问题,然后你分析跳转的问题,方法没问题那就是跳转的路径问题了
还有你加上这个属性:
<package name="liu" extends = "struts-default" namespace="/">
[解决办法]
楼主从以下几个方面找找:
若你创建的是一个dynamic Web project 工程,
首先,你看看工程properties——>java build path——>source——>default output folder————>projectName/WebContent/WEB-INF/classes(没改之前是projectName/build/classes)
其次,要看你选择的是server发布工程还是Tomcat启动发布,如果是每次启动/关闭Tomcat的话,那你就看看你的工程properties——>Tomcat——>选中 is a Tomcat project、
写入contextname-->/project name(一般是)
写入subdirectory set as web application root——> /WebContent
再次,看看你的D:\apache-tomcat-6.0.10\conf\Catalina\localhost目录下边是否有(context name)——>project name.xml
如果这些都配置没问题的话,那你就贴出异常信息我看看吧。
[解决办法]
我都服了
java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
这么明显的错误

热点排行