• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invoking servlet from another servlet

 
indra sen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to invoke face servlet from login servlet.
here is the web.xml file
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>login.LoginServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

I have tried
request.getRequestDispatcher("/Faces Servlet");
and
this.getServletContext().getRequestDispatcher("javax.faces.webapp.FacesServlet"));
both are returing null.can anybody help me...
Thanks in advance...
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the whitespace in "Faces Servlet" might cause this harm. Can you try removing the space (and it should look as that of LoginServlet) and run again?

For the second part, try replacing the "." with "/" but the path should be relative to the context root.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are the URL mappings for the servlets?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghavan Muthu:
I think the whitespace in "Faces Servlet" might cause this harm.


I guess servlet name can contain spaces.Leading and trailing spaces are ignored.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you cannot use /Faces Servlet.. its the servlet name.

What have you put in servlet-mapping ?
 
indra sen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>login.LoginServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


request.getRequestDispatcher(path);
and
this.getServletContext().getRequestDispatcher(path);
So, path means the <servlet-name> or <servlet-class> from web.xml?
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No,

see there is another <servlet-mapping> tag

<servlet-mapping>
<servlet-name>XYZ Servlet</servlet-name>
<url-pattern>/xyzservlet</url-pattern>
<servlet-mapping>

now you use /xyzservlet foe getting the request dispatcher.

Try this and see if it solves your problem.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing,

The <servlet-name> of <servlet-mapping> should match the
<servlet-name> of <servlet> tag..
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:
I guess servlet name can contain spaces.Leading and trailing spaces are ignored.


Thanks for the info Rahul. Let me try it out.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ask again, where are the URL mappings for the servlet? Why are you ignorning my and Amol Nayak's replies?
 
indra sen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amol ,it works ....
so it is the servlet mapping in web.xml
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"indraNJ sen",

Please check your private messages for an important message from me.

Kind regards,
Katrina Owen,
JavaRanch Saloon Bartender
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Check this SayThanks]http://faq.javaranch.com/view?SayThanks]SayThanks[/url][/url]

Even if one particular solution helped you fix your problem, please say thanks
to everyone saying which solution helped you..


Cheers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic