这个是JSP应用开发详解(第3版)的全部源代码!绝对的真实,绝对有用!
源代码在线查看: reg_ok.jsp
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
return "null";
}
%>
String problem,answer,province,education,selfintro,hobby;
String[] hobbies;
boolean regAttempt = false;
String errorMessage = "";
%>
//必须填写的项目
logname=request.getParameter("logname");
realname=request.getParameter("realname");
passwd1=request.getParameter("passwd1");
passwd2=request.getParameter("passwd2");
email=request.getParameter("email");
gender=request.getParameter("Gender");
//非必须填写的项目
phone=request.getParameter("phone");
if(phone.trim().equals("")){
phone=null;
}
problem=request.getParameter("problem");
if(problem.trim().equals("")){
problem=null;
}
answer=request.getParameter("answer");
if(answer.trim().equals("")){
answer=null;
}
province=request.getParameter("Province");
if(province.trim().equals("")){
province=null;
}
education=request.getParameter("education");
if(education.trim().equals("")){
education=null;
}
hobbies=request.getParameterValues("hobbies");
hobby="";
if(hobbies!=null){
for (int i=0;i hobby=hobby+hobbies[i];
}
}else hobby="null";
selfintro=request.getParameter("selfintro");
if(selfintro.trim().equals("")){
selfintro=null;
}
///转换中文
logname=getStr(logname);
realname=getStr(realname);
passwd1 =getStr(passwd1);
email=getStr(email);
gender =getStr(gender);
phone =getStr(phone);
problem =getStr(problem);
answer =getStr(answer);
province =getStr(province);
education=getStr(education);
hobby=getStr(hobby);
selfintro=getStr(selfintro);
%>
String sql="select ID from member where logname='"+logname+"'";
ResultSet RS=userBean.executeQuery(sql);
out.println(sql);
int rowscount=0;
try
{
while(RS.next())
{
rowscount++;
}
}
catch(Exception e)
{
}
//count.........
// out.println(rowscount);
if(rowscount==0)
{
regAttempt=true;
}else response.sendRedirect("error.jsp");
if(regAttempt==true)
{
String sqlinsert="insert into member(logname,realname,password,email,gender,phone,problem,answer,province,education,hobbies,selfintro) Values('"+logname+"','"+realname+"','"+passwd1+"','"+email+"','"+gender+"','"+phone+"','"+problem+"','"+answer+"','"+province+"','"+education+"','"+hobby+"','"+selfintro+"')";
out.println(sqlinsert);
userBean.executeQuery(sqlinsert);
response.sendRedirect("main.jsp");
}
%>