Guest User

Untitled

a guest
Sep 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Cannot access filter Servlet's session attribute from another normal Http Servlet
  2. public void doFilter(ServletRequest request, ServletResponse response,
  3. FilterChain chain) throws IOException, ServletException {
  4. HttpServletRequest httpReq = (HttpServletRequest) request;
  5. HttpServletResponse httpResp = (HttpServletResponse) response;
  6. HttpSession session = httpReq.getSession();
  7.  
  8. httpReq.setCharacterEncoding("UTF-8");
  9.  
  10. UserDTO dto = new UserDTO();
  11. session.setAttribute("system.userinfo", dto);
  12.  
  13. chain.doFilter(request, response);
  14.  
  15. }
  16.  
  17.  
  18. public class FileUpload extends HttpServlet {
  19. @SuppressWarnings("unchecked")
  20. public void doPost(HttpServletRequest request, HttpServletResponse response)
  21. throws ServletException, IOException {
  22. response.setContentType("text/html");
  23. response.setCharacterEncoding("UTF-8");
  24.  
  25. // cannot get anything here
  26. UserDTO userinfo = (UserDTO)request.getSession(false).getAttribute("system.userinfo");
  27.  
  28.  
  29. }
  30. }
Add Comment
Please, Sign In to add comment