为了账号安全,请及时绑定邮箱和手机立即绑定

跳转到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://img1.sycdn.imooc.com//57f50c820001d3aa11400620.jpg

正在回答

1 回答

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

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

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

0 回复 有任何疑惑可以回复我~
#1

qq_神烦男_0 提问者

非常感谢!
2016-10-06 回复 有任何疑惑可以回复我~
#2

OMG快到碗里来 回复 qq_神烦男_0 提问者

求解释一下,谢谢你啦
2017-04-25 回复 有任何疑惑可以回复我~
#3

OMG快到碗里来 回复 qq_神烦男_0 提问者

为毛我用request.getRequestDispatcher("userinfo.jsp").forward(request, response);就成功了
2017-04-25 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
JAVA遇见HTML——Servlet篇
  • 参与学习       160615    人
  • 解答问题       1029    个

本门课程在JSP课程的基础上,深入介绍Servlet的基础知识

进入课程

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信