This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No "welcome" page at all  RSS feed

 
Anthony Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
while using Tomcat, when you go http://localhost/ and land on http://localhost/index.jsp, you could use the jsp "forward" action to transfer control and the request object to a servlet.
You could use then the servlet to do whatever you need, but how do you supress the appearance of "index.jsp" in the URL I would like to see simply see:
http://localhost/
( or maybe something like: http://localhost/welcome)
Notice there is not ".html" or ".jsp" file in the URL
How do you do this?
Thanks
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that, if you generate the entire response within the servlet, you won't get that page at the end of the URL. Rather, the URL would terminate with the name of the servlet.
Indeed, I just tested it and that is the case.
Corey
 
John Fontana
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have more control over this with a servlet mapping...think of mapping "/*" to a controller servlet in an MVC pattern, for instance.
 
Anthony Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, asking a question is part of not knowing the contextual terminology/concepts/wordings
1._ I believe I am indeed generating the entire response within the servlet. I just got the RequestDispatcher as in:
try{
getServletConfig().getServletContext().getRequestDispatcher("/fielder.jsp"); }
catch(Exception X){ X.printStackTrace(); }
and the rest is exactly the SnoopServlet, which is working fine. (to me)
Also, how could the servlet response be seen in the browser if I am not generating it "entirely"? WHat do you mean? Could you simply post/send to me your example?
// - - - - - - - - - - - -
Regarding using servlet mapping, how do you map the JSP to the servlet? What exactly is the change you have to do in the web.xml file of this Webapp and the server.xml? Why mapping to "/*" and not to the actual servlet that I need the request to be sent to?
// - - - - - - - - - - - -
Again, I need to supress the default welcome page. How do you do this?
I just want to see something like http://www.mysite.com and decide with a servlet what is displayed as the default welcome page
Thanks very much
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example of a response that is generated entirely by the servlet. Rather than forwarding execution to a jsp, the HTML is written to the stream from the servlet, itself.

I hope that helps,
Corey
 
Anthony Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, even though I did not see any difference I tried your example, and go your HTML, but still:
http://localhost:8080/fielder.jsp
THis is exactly what I am trying to avoid, so maybe we were not on the same page. Jeez! Is what I am trying to do so difficult to get done/understand?
 
Anthony Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think now I see why we were not understanding each other.
Please, notice that I am referring to the welcome page NOT the default page of a Web Application.
 
Rishi Singh
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anthony,
you need to make the changes in the web.xml in servlet-mapping(servlet name and url-pattern).well the welcome page in your case is mapped to index.jsp which then delegates it to the servelet, if u don't want that jst change it to the servlet name and change the pattern too..give it a name of servlet
 
Anthony Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rishi,
Now I finally got it. For those of you who will encounter this thread looking to solve the same problem, this is how you do it.
1._ Your default page is determined by the "welcome-file" XML entry in your:
<tomcat_inst>conf\web.xml
configuration file. Notice this is ROOT's web.xml! NOT any of the other ones you will find for each web application.
2._ say your "welcome-file" entry looks like this (after installation)
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
You should only use the "index.jsp" entry because it is a jsp file what yo will be using to forward the request to the servlet. So comment out the whole previous <welcome-file-list> entry and just leave one that should look like:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
3._ so, <tomcat_inst>\ROOT\index.jsp simpy looks like:
<html>
<head><title>fielder</title></head>
<body>
<jsp:forward page="/servlet/BackStageServlet" />
</body>
</html>
4._ your compile servlet class should be:
<tomcat_inst>\webapps\ROOT\WEB-INF\classes\BackStageServlet.class
5._ then you should do the servlet-mapping to the url that the servlet engine will use to indetify this servlet like this.
<servlet>
<servlet-name>BackStage</servlet-name>
<servlet-class>BackStageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BackStage</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Hope it helped.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!