-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 に答える