例如:以下图片
要用servlet做
具体内容就是:先写一个表单,表单中有用户名,密码,登录,和注册,当点击注册时就会连接到另外一页面进行注册,当填完注册表中信息后,点击提交按钮,进行提交,并把注册的数据提交到数据库中去。然后返回登录页面进行登录其实具体就是不知道怎样把注册的数据怎样与数据库联系起来,也不知道在servlt类中怎样写。。请教大家,希望大家能帮个忙,也希望大家给出详细的代码...在此谢谢大家了

解决方案 »

  1.   

    给以前写代码是一样的、也要定义一个类用来连接数据库
    只不错利用servlet是用到action中间跳转页面而已
    然后在web.xml里面配置一下servlet就行了
    至于增删查改数据库里表的数据库
    和以前写的代码是一样的,没有区别
      

  2.   

    但是我在servlet的这个类中
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {。。}进行了查找和插入。。他报非法异常了
    我QQ是307195009   能不能QQ上聊留言好麻烦的。。
      

  3.   

    package servlet;import java.io.IOException;
    import java.io.PrintWriter;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import dao.LoginDao;public class LoginServlet extends HttpServlet { /**
     * 
     */
    private static final long serialVersionUID = 1L; /**
     * Constructor of the object.
     */
    public LoginServlet() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { doPost(request,response);
    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    request.setCharacterEncoding("gbk");
    response.setCharacterEncoding("gbk");
    ②///String name =request.getParameter("name");
    String pwd =request.getParameter("pwd");
    ////////////以上的是获得登录的名字和密码

    String age =request.getParameter("age");
    String sex =request.getParameter("sex");
    String degree =request.getParameter("degree");
    String phone =request.getParameter("phone");
    ③////String ic =request.getParameter("ic");
    /////////////////////从②到③是获得插入的值要把他传到数据库去,

    LoginDao ld=new LoginDao();
                     /////判断登录的名字和密码
    boolean bb=ld.login(name, pwd);
    if(bb){
    response.sendRedirect("/test_login/MyS.jsp");

    }else{
    response.sendRedirect("/test_login/defeater.jsp");

    }
              //////////判断插入的数据
    boolean bl=ld.insert(name, pwd, age, sex, degree, phone, ic);
    if(bl){
    response.sendRedirect("/test_login/MyS.jsp");

    }else{
    response.sendRedirect("/test_login/defeater.jsp");

    }


    out.flush();
    out.close();
    } /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
    // Put your code here
    }} 但我可以查找登录用户,可在数据库中用已注册用户进行登录,就是不能插入数据是不是②③处的代码有问题??