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

急struts2报404异常!所有分都送下

2012-07-23 
急急急!struts2报404错误!所有分都送上!现在在做一个项目,配置环境:tomcat6.0.35 + JDK1.6.0_30 + struts2

急急急!struts2报404错误!所有分都送上!
现在在做一个项目,配置环境:tomcat6.0.35 + JDK1.6.0_30 + struts2.3.1.2 + mysql5.0
但是form提交的时候,报404错误.
进入index.jsp提交后,报错“HTTP Status 404 - /huazhaosoft/manager.do”
type Status report

message /huazhaosoft/manager.do

description The requested resource (/huazhaosoft/manager.do) is not available.



index.jsp
<form name="form1" method="post" action="manager.do?action=login">

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>SSH</display-name>  
<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> 


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>  
  <constant name="struts.action.extension" value="do" />
  <constant name="struts.devMode" value="true" />
  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <package name="package" extends="struts-default" namespace="/huazhaosoft">  
  <action name="managerForm" path="/manager" scope="request" type="com.action.Manager" validate="true">  
  <forward name="managerLoginok" path="/welcome.jsp" />
  <forward name="error" path="/welcome.jsp" />
  </action>  
  </package>  
</struts> 


manager.java
package com.action;

import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.actionForm.ManagerForm;
import com.dao.ManagerDAO;
import javax.servlet.http.HttpSession;

public class Manager extends Action {
private ManagerDAO managerDAO = null;

public Manager() {
this.managerDAO = new ManagerDAO();
}

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String action = request.getParameter("action");
System.out.println("获取的查询字符串:" + action);
if (action == null || "".equals(action)) {
return mapping.findForward("error");
} else if ("login".equals(action)) {
return managerLogin(mapping, form, request, response);


} else if ("managerAdd".equals(action)) {
return managerAdd(mapping, form, request, response);
} else if ("managerQuery".equals(action)) {
return managerQuery(mapping, form, request, response);
} else if ("managerModifyQuery".equals(action)) {
return managerModifyQuery(mapping, form, request, response);
} else if ("managerModify".equals(action)) {
return managerModify(mapping, form, request, response);
} else if ("managerDel".equals(action)) {
return managerDel(mapping, form, request, response);
} else if ("querypwd".equals(action)) {
return pwdQuery(mapping, form, request, response);
} else if ("modifypwd".equals(action)) {
return modifypwd(mapping, form, request, response);
}
request.setAttribute("error", "操作失败!");
return mapping.findForward("error");
}

// 用户身份验证

public ActionForward managerLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ManagerForm managerForm = (ManagerForm) form;
managerForm.setName(managerForm.getName());
managerForm.setPwd(managerForm.getPwd());
int ret = managerDAO.checkManager(managerForm);
System.out.print("验证结果ret的值:" + ret);
if (ret == 1) {
HttpSession session = request.getSession();
session.setAttribute("manager", managerForm.getName());
return mapping.findForward("managerLoginok");
} else {
request.setAttribute("error", "您输入的用户名称或密码错误!");
return mapping.findForward("error");
}
}

}


managerForm.java

package com.actionForm;

import org.apache.struts.action.ActionForm;

public class ManagerForm extends ActionForm {
  private Integer id=new Integer(-1); //用户ID号
  private String name=""; //用户名称
  private String pwd=""; //用户密码
  private int sysset=0; //系统设置权限
  public Integer getId() {
  return id;
  }

  public void setId(Integer id) {
  this.id = id;
  }

  public void setPwd(String pwd) {
  this.pwd = pwd;
  }

  public void setName(String name) {
  this.name = name;
  }

  public String getName() {
  return name;
  }

  public String getPwd() {
  return pwd;
  }

  public void setSysset(int sysset){
  this.sysset=sysset;
  }
  public int getSysset(){
  return sysset;
  }
}

ConnDB.java

package com.core;

import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class ConnDB {
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
private static String propFileName = "/com/connDB.properties";//指定资源文件保存的位置
private static Properties prop = new Properties();
private static String dbClassName ="com.mysql.jdbc.Driver";
private static String dbUrl = "";
public ConnDB(){
try {
InputStream in=getClass().getResourceAsStream(propFileName);
prop.load(in);//通过输入流对象加载Properties文件
dbClassName = prop.getProperty("DB_CLASS_NAME");//获取数据库驱动
dbUrl = prop.getProperty("DB_URL",
"jdbc:mysql://127.0.0.1:3306/db_company?user=root&password=root&useUnicode=true");
}
catch (Exception e) {


e.printStackTrace();//输出异常信息
}
}

public static Connection getConnection() {
Connection conn = null;
try {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl);
}
catch (Exception ee) {
ee.printStackTrace();
}
if (conn == null) {
System.err.println(
"警告: DbConnectionManager.getConnection() 获得数据库链接失败.\r\n\r\n链接类型:" +
dbClassName + "\r\n链接位置:" + dbUrl);
}
return conn;
}

/*
* 功能:执行查询语句
*/
public ResultSet executeQuery(String sql) {
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}

/*
* 功能:执行更新操作
*/
public int executeUpdate(String sql) {
int result = 0;
try {
conn = getConnection();//调用getConnection()方法构造Connection对象的一个实例conn
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);//执行更新操作
} catch (SQLException ex) {
result = 0;
}
return result;
}

/*
* 功能:关闭数据库的连接
*/
public void close() {
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}

managerDAO.java

package com.dao;

import com.core.*;
import java.util.*;
import com.actionForm.ManagerForm;
import java.sql.*;
import java.*;

public class ManagerDAO {
  private ConnDB conn = new ConnDB();
  //查询数据
  public Collection query(String queryif) {
  ManagerForm managerForm = null;
  Collection managercoll = new ArrayList();
  String sql = "";
  if (queryif == null || queryif == "" || queryif == "all") {//当参数queryif的值为null、all或空时查询全部数据
  sql = "select m.*,p.purview from tb_member m left join tb_purview p on m.id=p.id";
  }else{
  sql="select m.*,p.purview from tb_member m left join tb_purview p on m.id=p.id where m.name='"+queryif+"'";//此处需要应用左连接
  }
  ResultSet rs = conn.executeQuery(sql);//执行SQL语句
  try {//捕捉异常信息
  while (rs.next()) {
  managerForm = new ManagerForm();
  managerForm.setId(Integer.valueOf(rs.getString(1)));
  managerForm.setName(rs.getString(2));
  managerForm.setPwd(rs.getString(3));
  managerForm.setSysset(rs.getInt(4));
  managercoll.add(managerForm);//将查询结果保存到Collection集合中
  }
  } catch (SQLException e) {}
  return managercoll;//返回查询结果
  }

  //管理员身份验证
  public int checkManager(ManagerForm managerForm) {
  int flag = 0;
  //ChStr chStr=new ChStr();
  String sql = "SELECT * FROM tb_member where name='" +
  managerForm.getName() + "'";
  ResultSet rs = conn.executeQuery(sql);
  try {
  if (rs.next()) {
  String pwd = managerForm.getPwd();//获取输入的密码并过滤输入字符串中的危险字符
  if (pwd.equals(rs.getString(3))) {


  flag = 1;
  } else {
  flag = 0;
  }
  }else{
  flag = 0;
  }
  } catch (SQLException ex) {
  flag = 0;
  }finally{
  conn.close();
  }
  return flag;
  }

 }


[解决办法]
jsp可以进去,点提交报404,应该是配置问题,1可能是action的路径,2可能是forward jsp的路径
这两个其中一个配置不对找不到,所以报404,大致看了一下,你可以把jsp的路径写全一些试试
[解决办法]
<package name="package" extends="struts-default" namespace="/huazhaosoft">
你的namespace是在/huazhaosoft下找这个action的。

而你的页面请求的action是
<form name="form1" method="post" action="manager.do?action=login">


按照你struts.xml配置的话 前台的jsp页面的action应该改为

<form name="form1" method="post" action="/huazhaosoft/managerForm.action">


看了看你struts配置 把我写的action变成你的do 试试。
[解决办法]

探讨
jsp可以进去,点提交报404,应该是配置问题,1可能是action的路径,2可能是forward jsp的路径
这两个其中一个配置不对找不到,所以报404,大致看了一下,你可以把jsp的路径写全一些试试

[解决办法]
探讨
<package name="package" extends="struts-default" namespace="/huazhaosoft">
你的namespace是在/huazhaosoft下找这个action的。

而你的页面请求的action是
<form name="form1" method="post" action="manager.do?action=login……

[解决办法]
action 的名字和页面的名字不一致 肯定报找不到action的错啊 晕
[解决办法]
description The requested resource (/huazhaosoft/manager.do) is not available.
很明显没有这个action(/huazhaosoft/manager.do)

改成<form name="form1" method="post" action="managerForm.do?action=login">


[解决办法]
你的manager 在Struts.xml 中就根本没有配置
在Struts.xml中需要说明
<action name="manager" class="xxx">
...
</action>
[解决办法]
你的struts配置文件写的很烂啊我真的不想看,你自己看下struts文档吧,提示你struts2默认的后缀是.action而不是.do。还有就是你这明显是用怎么配置struts1的方式配置struts2,其实升级后这个框架改变了很多。你自己好好看下吧.
[解决办法]
探讨
现在在做一个项目,配置环境:tomcat6.0.35 + JDK1.6.0_30 + struts2.3.1.2 + mysql5.0
但是form提交的时候,报404错误.
进入index.jsp提交后,报错“HTTP Status 404 - /huazhaosoft/manager.do”
type Status report

message /huazhaosoft/manag……

[解决办法]
后台action与前台form提交请求action路径不对应的

热点排行