81,092
社区成员
发帖
与我相关
我的任务
分享
<?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>
<?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>
<%@ 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>
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;
}
}
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";
}
}
}
<action name="password" class="com.user.action.ApproveAction" method="approve">
<result name="no">/error.jsp</result>
<result name="ok">/welcome.jsp</result>
</action>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
少年,filter没有配置maping