假设登陆页面logon.jsp提交的Form表单包含“name”和”password”两个元素,编写一个简单的Servlet,获取登陆信息,并将登陆信息保存到session中。并编写一个Filter来处理此请求的中文问题(不需要在web.xml文件中定义及映射此过滤器)。

解决方案 »

  1.   

    编写一个Filter来处理此请求的中文问题(不需要在web.xml文件中定义及映射此过滤器)。这个不清楚。
      

  2.   

    servlet,filter,listener...这些组件是sun的J2EE规范里面的web组件。你说要不要写到web.xml里面去??
      

  3.   

    Interface ServletRequest
    这是设置编码的方法 
    void setCharacterEncoding(java.lang.String env) 
              Overrides the name of the character encoding used in the body of this request.  
    这是放到session的方法Interface HttpServletRequest 我们一般使用的是这个request
    里面有个方法 getsession()
    HttpSession getSession() 
              Returns the current session associated with this request, or if the request does not have a session, creates one. 
    这哥使我们常用的session
    Interface HttpSession
    里面的
     void setAttribute(java.lang.String name, java.lang.Object value) 
              Binds an object to this session, using the name specified.  即可保存对象到session下面的语句即调用session保存对象的request.getSession().setAttrubute(java.lang.String name, java.lang.Object value);
      

  4.   


    request.setCharacterEncoding("gbk");  
    String username = request.getAttribute("name");
    String password = request.getAttribute("password");
    User u = new User(username,password);
    request.getSession().setAttribute("userInfo",u);