📄 registeraction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.tang.struts.action;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.tang.foruse.GetConn;
import com.tang.struts.form.RegisterForm;
/**
* MyEclipse Struts
* Creation date: 05-14-2008
*
* XDoclet definition:
* @struts.action input="/reg.jsp" validate="true"
*/
public class RegisterAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
//���ڴ����û�ע��
String target = "failure" ;
RegisterForm myform = (RegisterForm)form;
GetConn gc = new GetConn();
Connection conn = null;
PreparedStatement pstm = null;
conn= gc.GetConnectioon();
ActionErrors errors = new ActionErrors();
try {
pstm = conn.prepareStatement("insert into users values(null,?,?,null,?,?,?,?)");
pstm.setString(1, myform.getUsername());
pstm.setString(2 ,myform.getPassword());
pstm.setString(3, myform.getEmail());
pstm.setString(4, myform.getAddress());
pstm.setLong(5, myform.getZipcode());
pstm.setLong(6, myform.getPhonenum());
int i = pstm.executeUpdate();
if(i!=1)
{
ActionMessage msg = new ActionMessage("ע��ɹ�",false);
errors.add("register",msg);
request.setAttribute(org.apache.struts.Globals.ERROR_KEY, msg);
}
else
target = "success";
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
try {
if(pstm!=null)
{
pstm.close();
pstm = null;
}
if(conn!=null&&!conn.isClosed()){
conn.close();
conn = null;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return mapping.findForward(target);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -