问答详情
源自:1-11 Servlet获取表单数据

跳转到servlet界面就没反应了。。。。

package servlet;


import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.Date;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import entity.user;


/**

 * Servlet implementation class servlet1

 */

public class servlet1 extends HttpServlet {

private static final long serialVersionUID = 1L;

       

    /**

     * @see HttpServlet#HttpServlet()

     */

    public servlet1() {

        super();

        // TODO Auto-generated constructor stub

    }


/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doPost(request, response);

}


/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

request.setCharacterEncoding("utf-8");

user u = new user();

String username,password,email,introduce,font,gender;

Date birthday;

String[] hobby;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");

try {

username = request.getParameter("username");

password = request.getParameter("password");

email = request.getParameter("email");

introduce = request.getParameter("introduce");

birthday = sdf.parse(request.getParameter("brithday"));

hobby = request.getParameterValues("hobby");

gender = request.getParameter("gender");

if(request.getParameter("isAccept")!=null){

font = "ture";

}

else{

font = "faslt";

}

//给实体对象赋值

u.setBirthday(birthday);

u.setEmail(email);

if(font.equals("ture")){

u.setFont("ture");

}

else{

u.setFont("false");

}


u.setGender(gender);

u.setHobby(hobby);

u.setIntroduce(introduce);

u.setName(username);

u.setPassword(password);

//把注册成功的对象保存在session当中

request.getSession().setAttribute("regUser", u);

//跳转到注册成功的页面

request.getRequestDispatcher("../userinfo.jsp").forward(request, response);

} catch (Exception e) {

// TODO: handle exception

}

}

public void init() throws ServletException {

// Put your code here

}


}

http://img.mukewang.com/57f50c820001d3aa11400620.jpg

提问者:qq_神烦男_0 2016-10-05 22:22

个回答

  • Sun重阳
    2016-10-06 10:55:00
    已采纳

    //跳转到注册成功的页面

    request.getRequestDispatcher("../userinfo.jsp").forward(request, response);

    这里你应该使用绝对路劲!!!