registeraction.java
来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· Java 代码 · 共 136 行
JAVA
136 行
package com.sztheater.biz.register;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import java.sql.*;
import com.sztheater.framework.web.*;
import com.sztheater.framework.util.*;
import java.util.*;
import javax.servlet.http.*;
public class RegisterAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException {
HashMap userinfo = null; //用户信息包括customer_id和username=lastname
userinfo = new HashMap();
int iSuccFlag = 0;
int iExistsNum =0;
String strMsg = "";
String strSQL = "";
String CustomerID = "";
ResultSet rs = null;
Statement st = null;
Connection conn = null;
HttpSession _httpsession = null;
_httpsession = request.getSession();
String target = new String("success");
String username = ((RegisterForm)form).getUsername();
String password = ((RegisterForm)form).getPassword();
String Truename = ((RegisterForm)form).getTruename();
String Sex = ((RegisterForm)form).getSex();
String Age = ((RegisterForm)form).getAge();
String Telnumber = ((RegisterForm)form).getTelnumber();
String Email = ((RegisterForm)form).getEmail();
String getIDCard = ((RegisterForm)form).getIDCard();
String Pwdquestion = ((RegisterForm)form).getPwdquestion();
String Pwdanswer = ((RegisterForm)form).getPwdanswer();
String interest = request.getParameter("love");//用户兴趣
((RegisterForm)form).setInterest(interest);
/* 进行数据库操作*/
try{
try{
conn = DbFunc.getConnection(false);
}catch(Exception e){
iSuccFlag = -90102;
if(conn!=null) DbFunc.free(conn,iSuccFlag);
conn = null;
strMsg = "服务取数据库连接异常"+e.getMessage();
System.out.println("strMsg"+strMsg);
}
//取得执行数据库操作Statement
st = conn.createStatement();
strSQL = "select count(*) as num \n"
+ "from T_NetCustomer \n"
+ "where LoginName = '"+username+"'";
rs = st.executeQuery( strSQL);
if (rs!=null && rs.next()){
iExistsNum = rs.getInt("num");
}
rs.close();
rs = null;
if(iExistsNum>0){
target="failure";
return mapping.findForward(target);
}
strSQL = "insert into T_customer(LastName,Tel,IsNetCustomer) \n"
+ "values('"+username+"','"+Telnumber+"','1')";
iSuccFlag = DbFunc.runsql(strSQL);
System.out.println("iSuccFlag="+iSuccFlag);
//插入T_customer表成功
if (iSuccFlag>0){
strSQL = "select CustomerID from T_customer where LastName='"+username+"'";
rs = st.executeQuery(strSQL);
if (rs!=null && rs.next()){
CustomerID = rs.getString("CustomerID");
}
strSQL = "insert into T_NetCustomer(CustomerID,LoginName,Passward,\n"
+"Email,TrueName,Sex,Age,Telnumber,IDCard,Interest,\n"
+"Pwdquestion,Pwdanswer )\n"
+ "values('"+CustomerID+"','"+username+"','"+password+"','"+Email+"',\n"
+"'"+Truename+"','"+Sex+"','"+Age+"','"+Telnumber+"','"+getIDCard+"', \n"
+"'"+interest+"','"+Pwdquestion+"','"+Pwdanswer+"') ";
iSuccFlag = DbFunc.runsql(strSQL);
if (iSuccFlag>0) {
target="success";
userinfo.put("username",username);
userinfo.put("customerid",CustomerID);
_httpsession.setAttribute("username",username);//把用户名压入session
_httpsession.setAttribute("userinfo",userinfo);//把用户信息压入session
}
}else{
target="failure";
return mapping.findForward(target);
}
rs.close();
rs = null;
} catch(Exception e){
iSuccFlag = 20102005;
strMsg = e.getMessage();
strMsg = "失败!";
}finally{
try{
if(rs!=null) rs.close();
}catch(Exception e1){
}
try{
if(st!=null) st.close();
if(conn!=null) conn.close();
}catch(Exception e1){
}
rs= null;
st= null;
}
return (mapping.findForward(target));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?