java web actionq请求404错误?

zktalk 2016-06-24 10:41:57
请大家帮我看看哪里出错了??
结构

web.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<web-app 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/web-app_2_4.xsd"
version="2.4">

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<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="com" extends="struts-default">
<action name="password" class="com.user.action.ApproveAction">
<result name="no">/error.jsp</result>
<result name="ok">/welcome.jsp</result>
</action>
</package>
</struts>

index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
</head>
<body>
<h1>用户验证</h1>

<form action="password.action" method="post">
认证码:<input type="text" name="pass" value="" /><br>
<input type="submit" value="验证" />
</form>


</body>
</html>

Dao.java
package com.user.dao;

import java.sql.*;

public class Dao {
Connection con = null;
Statement stat = null;
ResultSet rs = null;

public Dao() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/approve", "root", "1234");
stat = con.createStatement();
} catch (Exception e) {
// TODO: handle exception
con = null;
}
}

public ResultSet executeQuery(String sql) {
try {
rs = stat.executeQuery(sql);
} catch (Exception e) {
// TODO: handle exception
rs = null;
}
return rs;
}

public int executeUpdate(String sql) {
try {
stat.executeUpdate(sql);
return 0;
} catch (Exception e) {
// TODO: handle exception
}
return -1;
}
}

ApproveAction.java
package com.user.action;

import java.sql.*;
import com.opensymphony.xwork2.ActionSupport;
import com.user.dao.Dao;


@SuppressWarnings("serial")
public class ApproveAction extends ActionSupport {
private Dao dao = new Dao();
private String pass;

public String getPass() {
return pass;
}

public void setPass(String pass) {
this.pass = pass;
}

public String approve() {
String sql = "select * from register where pass=" +getPass();
String upd = "update register set type=1 wherepass="+getPass();
ResultSet rS = dao.executeQuery(sql);
try {
if (rS.next()) {
ResultSet rSa = dao.executeQuery(upd);
return "ok";
}
return "no";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "ok";
}
}



}
...全文
303 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
47写bug 2016-06-29
  • 打赏
  • 举报
回复
这种情况一般都先检查web.xml看看有没有写错
lwp_trouble 2016-06-25
  • 打赏
  • 举报
回复
web.xml里没有没配filtermapping
zktalk 2016-06-24
  • 打赏
  • 举报
回复
引用 2 楼 jing150428 的回复:
struts2 的配置文件 中 aciton节点 却 method="approve" method属性 默认是 excute
改了还是404啊..
zktalk 2016-06-24
  • 打赏
  • 举报
回复
引用 2 楼 jing150428 的回复:
struts2 的配置文件 中 aciton节点 却 method="approve" method属性 默认是 excute
具体是哪??? 改成这样?struts.xml中
<action name="password" class="com.user.action.ApproveAction" method="approve">
			<result name="no">/error.jsp</result>
			<result name="ok">/welcome.jsp</result>
		</action>
子夜静舞 2016-06-24
  • 打赏
  • 举报
回复
struts2 的配置文件 中 aciton节点 却 method="approve" method属性 默认是 excute
zktalk 2016-06-24
  • 打赏
  • 举报
回复
报错
  • 打赏
  • 举报
回复

<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
少年,filter没有配置maping
鸟与树 2016-06-24
  • 打赏
  • 举报
回复
引用 6 楼 zhangkan111 的回复:
[quote=引用 5 楼 qq_15776091 的回复:] 地址输入的有问题。根据楼主的代码来看,form里面的action是不对的。
请问password.action 不对吗?[/quote] 不对的。。对就不会出现404了。。。你可以先在浏览器地址栏里面试调用你的action,在后台加个断点调试。 具体地址嘛,我很久没有用过struts2了,记不太清楚了。。你看一下相关文档吧
zktalk 2016-06-24
  • 打赏
  • 举报
回复
引用 5 楼 qq_15776091 的回复:
地址输入的有问题。根据楼主的代码来看,form里面的action是不对的。
请问password.action 不对吗?
鸟与树 2016-06-24
  • 打赏
  • 举报
回复
地址输入的有问题。根据楼主的代码来看,form里面的action是不对的。

81,092

社区成员

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

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