0

Am hitting my Servlet from a link. Some Cookies would have been already set in Client. When my Servlet is hit, I want to retrieve these Cookies.

For eg., am hitting the link like http:/myDomain/myServlet/ServletReceiver

In web.xml, I have below code

<servlet>
   <display-name>ServletReceiver</display-name>
   <servlet-name>ServletReceiver</servlet-name>
   <servlet-class>(location of my ServletReceiver)</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>ServletReceiver</servlet-name>
   <url-pattern>/ServletReceiver</url-pattern>
 </servlet-mapping>

And my ServletReceiver code is below

public class ServletReceiver extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Cookie[] cookies = request.getCookies();
    // Do some checks here based on cookies obtained and redirect to corresponding page
    RequestDispatcher dispatcher=request.getRequestDispatcher("/pages/index.jsf");
    dispatcher.forward(request, response);
 }
 }

My requirement is, when I retrieve some data from Cookies, I want to set it into bean. And since am creating an instance of the bean in CustomPhaselistener (and not in ServletReceiver), if I get the request object through which I can get cookie values then I can set that in my bean in PhaseListener.

My bean is request scoped.

So, is there a way to get request object in CustomPhaseListener?

Also, am retrieving Cookies in doGetmethod. Is that suggested?

Am using JSF 1.2

Vikas V
  • 3,176
  • 2
  • 37
  • 60
  • why dont you do it with session? – MaVRoSCy Nov 07 '12 at 09:22
  • @MaVRoSCy Sorry. I didn't get you exactly. You meant to say make my bean Session scoped ? Or, you meant to say share my values in Session attributes and retrieve that in PhaseListener? I don't want to make bean as Session scoped because its a simple page which takes input from Users and I want input fields not to be pre populated with earlier values when users makes a new request. – Vikas V Nov 07 '12 at 09:52
  • Share values through session attributes – MaVRoSCy Nov 07 '12 at 10:15
  • @MaVRoSCy Am not sure doing so would be the correct way in my `Controller` (in my `doGet` method). So, am looking for a way in my PhaseListener. Please suggest – Vikas V Nov 07 '12 at 10:22

0 Answers0