Announcement Announcement Module
Collapse
No announcement yet.
Header, response and redirect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Header, response and redirect

    Hi,

    I am trying to create a temp redirect controller that passes the header to the main application page for spring pre-authentication mock. I can use browser based firebug(firefox), SOAPUI or postman(chrome) to simulate sending the header in to the URL but cannot achieve this programatically.

    The request comes from the login.jsp page and the controller captures the username form the POST, which it needs to pass to the header. After the redirect, the header is lost since the redirect fires a new HTTP request. Is there a way to maintain the header in the redirect in spring or basic servlet API’s?

    Here is the sample code:

    Code:
        @RequestMapping(value = "/entrypoint", method = RequestMethod.POST)
        public void redirectMe(@RequestParam("username") final String userName,
                final HttpServletRequest request, final HttpServletResponse response) {
    
            try {
    
                response.setHeader("username", userName);
                // final RequestDispatcher rd = request.getRequestDispatcher("/");
                // rd.forward(request, response);
    
                response.sendRedirect("/app-opsissuemgr/");
            } catch (final Exception e) {
                // TODO: handle exception
                log.error(e.getMessage());
            }
    
        }
    I have also tried the forwarding from the same, that works but the url is not changed and the page formating is off

    Code:
        @RequestMapping(value = "/entrypoint", method = RequestMethod.POST)
        public void redirectMe(@RequestParam("username") final String userName,
                final HttpServletRequest request, final HttpServletResponse response,
                final HttpServlet servlet) {
    
            try {
    
                final ServletContext context = servlet.getServletContext();
    
                response.setHeader("username", userName);
                final RequestDispatcher rd = context.getRequestDispatcher("/");
                rd.forward(request, response);
    
                // response.sendRedirect("/app-opsissuemgr/");
            } catch (final Exception e) {
                // TODO: handle exception
                log.error(e.getMessage());
            }
    
        }
    your help is greatly appreciated.

    Cheers!
    Last edited by sijaffer; Jun 4th, 2013, 04:11 PM.

  • #2
    From the server you cannot influence the client (at least not that much). The header is send from the server to the client. The client then issues a new request (the redirect) but only submits its own headers, not the headers you choose to add.

    If you want to do something like this you would have to do it in the client and as such probably in JavaScript.

    Comment

    Working...
    X