aspose file tools*
The moose likes Servlets and the fly likes how to read values after request.dispatch() or sendRedirect? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to read values after request.dispatch() or sendRedirect?" Watch "how to read values after request.dispatch() or sendRedirect?" New topic
Author

how to read values after request.dispatch() or sendRedirect?

satish kinikiri
Greenhorn

Joined: Nov 16, 2010
Posts: 5
In my filter i have requirement of showing user a message with ok cancel option.
if the user opts for ok then i have continue to the filter chain, if user opts for cancel then i need to redirect him some other page say error.jsp
I am trying as shown below

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {


String url = "/jsp/message.jsp";
/*HttpServletResponse httpRes = (HttpServletResponse)response;
httpRes.sendRedirect(url);*/

RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
requestDispatcher.forward(request, response);
if(gotOKfrom message.jsp){
return or chain.doFilter(request, response);

} if( got cancel from message.jsp){

RequestDispatcher requestDispatcher = request.getRequestDispatcher("error.jsp");
requestDispatcher.forward(request, response);

}


System.out.println("am here returned..");
/chain.doFilter(request, response);
}




*****************

Please let me how to read what option user has selected from message.jsp

thanks
Advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
I think the logic you are trying to do in a Filter belongs in a servlet.

Bill
satish kinikiri
Greenhorn

Joined: Nov 16, 2010
Posts: 5
Yes my filter implements public abstract interface javax.servlet.Filter
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61774
    
  67

You cannot interrupt the filter chain to obtain input form the user. As William indicated, you'll need to use another approach.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

Well, you can forward or redirect a request from a filter. It's the part about expecting the subsequent request to come back into the filter and continue where the previous request left off which it doesn't work like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to read values after request.dispatch() or sendRedirect?