-1

嗨,请有人在这个问题上帮助我。

我有一个扩展 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");
  }
}
4

1 回答 1

0

没有这样的方法protected void doGet(HttpServletRequest request) throws ServletException, IOException

方法签名是:

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

于 2012-11-09T07:14:12.210 回答