这是我的代码你看了就懂了,方法是一样的
HandleRegister.java
package bean;
import bean.BaseDAO;
import bean.Regiser;
import bean.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleRegister extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
BaseDAO bd = new BaseDAO();
Regiser reg = new Regiser();
request.setAttribute("regiser",reg);
String logname=request.getParameter("logname").trim();
String password=request.getParameter("password").trim();
String email=request.getParameter("email").trim();
String phone=request.getParameter("phone").trim();
String message=request.getParameter("message");
String backNews="";
try{String insert="insert into member values ('"+logname+"','"+password+"','"+phone+"','"+email+"','"+message+"')";
int n=bd.Exec(insert);
if(n!=0){
backNews="注册成功";
reg.setBackNews(backNews);
reg.setLogname(logname);
reg.setEmail(email);
reg.setPassword(password);
reg.setMessage(message);
reg.setPhone(phone);
}
}
catch(Exception exp){
backNews="该用户名已被使用";
reg.setBackNews(backNews);
}
RequestDispatcher dispather=request.getRequestDispatcher("showRegister.jsp");
dispather.forward(request, response);
}
}
显示页面showRegister.jsp
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
My JSP 'showRegister.jsp' starting page用户名: | |
密码: | |
电话: | |
邮箱: | |
简介: |
其中还有俩个java文件,一个是存放模型的get和set方法的,一个是表单。你既然写到这里了你应该懂得。我就不贴出来了
也可以用${regiser.logname }直接调用,显示出来,这个就不详细解释