嗨,请有人在这个问题上帮助我。
我有一个扩展HttpServlet的类和一个名为doGet的方法(HttpServletRequest request)
但是我没有HttpServletResponse。现在我想回应客户的请求,因为我没有响应我如何回应请求。我可以创建能够在该类中使用反射动态创建它并且是他们的任何其他方式..我的问题伪代码如下所示
protected void doGet(HttpServletRequest request)throws ServletException, IOException {//having only request as parameter in doGet()
//Want to respond to a jsp with out having a response
//how can i create a response object if i got a HttpServletResponse response the code looks as follows
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String name = request.getParameter("username");
String password = request.getParameter("password");
if(name.equals("James")&& password.equals("abc")){
response.sendRedirect("result.jsp");
}
else{
pw.println("u r not a valid user");
}
}
答案 0 :(得分:0)
没有这样的方法protected void doGet(HttpServletRequest request) throws ServletException, IOException
方法签名是:
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException