Re: Multiple RequestProcessor in one Struts Application
Posted By:
Anonymous
Posted On:
Sunday, December 26, 2004 11:41 AM
u r not supposed to use two or 3 req processor sin struts-congig.xml ..
but u can trace from which action the req comes .. depending on that do something forwarding or retruning false..
see the below snippet
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.RequestProcessor;
/**
* @author administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CustomRequestProcessor extends
RequestProcessor {
protected boolean processPreprocess(HttpServletRequest request,HttpServletResponse response) {
HttpSession session =
request.getSession(false);
//If user is trying to access login page then dont check
if( request.getServletPath().equals
("/loginInput.do") || request.getServletPath().equals("/login.do") )
return true;
//Check if userName attribute is there is session. If yes then that means user has allready loggedIn
if( session != null && session.getAttribute("userName") != null)
return true;
else{
try{
//If no redirect user to login Page
request.getRequestDispatcher("/Login.jsp").forward(request,response);
}catch(Exception ex){
}
}
return false;
}
protected void processContent(HttpServletRequest
request,HttpServletResponse response) {
//Check if user is requesting
ContactImageAction if yes then set image/gif as content type
if( request.getServletPath().equals("/contactimage.do")){
response.setContentType("image/gif");
return;
}
super.processContent(request, response);
}
}
grgowtham_cse@yahoo.com is my id if u want further clarification