daily pastebin goal
87%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top