Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cannot access filter Servlet's session attribute from another normal Http Servlet
- public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- HttpServletRequest httpReq = (HttpServletRequest) request;
- HttpServletResponse httpResp = (HttpServletResponse) response;
- HttpSession session = httpReq.getSession();
- httpReq.setCharacterEncoding("UTF-8");
- UserDTO dto = new UserDTO();
- session.setAttribute("system.userinfo", dto);
- chain.doFilter(request, response);
- }
- public class FileUpload extends HttpServlet {
- @SuppressWarnings("unchecked")
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html");
- response.setCharacterEncoding("UTF-8");
- // cannot get anything here
- UserDTO userinfo = (UserDTO)request.getSession(false).getAttribute("system.userinfo");
- }
- }
Add Comment
Please, Sign In to add comment