aspose file tools*
The moose likes JSP and the fly likes 404 error redirecting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "404 error redirecting" Watch "404 error redirecting" New topic
Author

404 error redirecting

ramakrishna madati
Greenhorn

Joined: Mar 15, 2005
Posts: 9
Hello all,

firstly very good place for me to land in.

Iam working on a website. My host has given me details of where to put my jsp files. Its something like myservlets/jsp under my domain..

1] i have to use www.mydomain.com/myservlets/jsp/some.jsp to invoke my jsp. But i want to use only www.mydomain.com/some.jsp only. How do i do it?

2]. also i want to know about 404 error page redirecting.. How do i do it. at my website.

Pl also tell me how do it at my desktop Iam using Apache Tomcat 4.1

Thanks in anticipation of reply..

madati.
[ March 15, 2005: Message edited by: Bear Bibeault ]
ramakrishna madati
Greenhorn

Joined: Mar 15, 2005
Posts: 9
please anybody reply...
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624


1] i have to use www.mydomain.com/myservlets/jsp/some.jsp to invoke my jsp. But i want to use only www.mydomain.com/some.jsp only. How do i do it?

The best way would be to use a MVC (Model View Controller) architecture, such Struts. Alternatively, you could map it in your Deployment Descriptor (i.e. web.xml) like such:


The user would then navigate to www.mydomain.com/MyPage (or www.mydomain.com/myservlets/jsp/some.jsp) to get to the JSP page.


2]. also i want to know about 404 error page redirecting.. How do i do it. at my website.

For web application wide 404 page handling via a custom error page, place something similar to the following in your Deployment Descriptor (i.e. your web.xml file).

Take a look at the sample chapter 5 "Controlling Web Application Behavior with web.xml" from the book More Servlets and JavaServer Pages for more information. You can download it from the book's website www.moreservlets.com. It is a great resource on understanding the deployment descriptor file (i.e. web.xml). Of course, the book is an even better resource for understanding Servlets & JSPs as a whole You may also want to look at using a MVC framework such as Struts, but there is a bit of a learning curve in doing so.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If the hosting company configures the app server for you, this will be difficult.

Have you asked them why, your app isn't configured as the default context for that domain?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Adopting the use of Struts, or any other framework, cannot achieve this. As Ben pointed out, it must be set up by the hosting company (or whoever has control of the server setup). It cannot be done from within the web application.

Redirecting 404 errors can be achieved via web.xml entries to define error handling.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Good point Ben & Bear. I'm so use to having direct control over both my Solaris box and my App Server that I failed to think about the possibility the hosting company may not give access to the user to configure the app/web server.
ramakrishna madati
Greenhorn

Joined: Mar 15, 2005
Posts: 9
Thankyou Mark, Ben, Bear for your replies.. I have intimated my host to make necessary changes..

But I haven't been able to make those changes on my desktop..I use Tomcat 4.1 and I made a search for web.xml I came up with more than 15 results for it.. one each under conf, webapps\examples\WEB-INF, webapps\ROOT\WEB-INF and many more..

which file should i modify for adding the following lines for 404 error pae redirecting..
<error-page>
<error-code>404</error-code>
<location>/examples/jsp/error404.jsp</location>
</error-page>

[I have added the above lines in web.xml file under conf file.. i have restarted ther server but nothing seems to happen when i provide invalid URL]

Thanx..
madati
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

For Tomcat, you make your app the default context by editing server.xml in your tomcat_home/conf directory. By default the context named "ROOT" is the default.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

To give you some more information...

The web.xml file, formally known as the deployment descriptor, is something you would write for your web application, assuming you are using the recommend Java Web Application structure and deployment. Web Application are the recommended and preferred method of organizing and deploying a website.

One of the primary advantages of a Web Application is that it is (typically) completely self contained. Within a single zip like file, a .war file (WAR = Web Archive) is not only your entire Website's HTML, images, JSP's and Servlets, but any Java Libraries, and the deployment descriptor. This results in the ability to deploy and configure a website via a single file. Typically there is nothing additional to configure in the Web Server (or App Server). Before Web Applications, you typically need to either manually configure the classpath, servlet paths, and other things in the Web Server, or write scripts to do such in a consistent manner if deploying across multiple servers. The deployment descriptor, or web.xml file, now contains all this information. As such, it is an extremely important file, but also one that can have a bit of a learning curve to it.

The web.xml files you found in your search are ones from examples included with TomCat and for the TomCat server itself. As Ben mentions, for TomCat, the default app is in the directory ROOT.

You can read the ONJava.com article Java Web Applications for a very brief and high-level overview of what a web application is. Then you can look at the article Deploying Web Applications to Tomcat. These articles will give you a basic understanding of Web Applications. You can also look at the Sun Tutorial on Web Applications. The Sun tutorial does a good job of explaining web applications. You can then also tale a look at the sample chapter I referenced above as an excellent web.xml specific resource.reference.

For further more in depth reading on the subject of Web Applications, I would recommend looking at a good book on JSP & Servlets, most of which discuss Web Applications. Some recommendations would be Head First Servlets & JSP, JavaServer Pages, or Core Servlets and JavaServer Pages: Volume 1: Core Technologies. While Core Servlets is in its second edition, the first edition is available as a free PDF download.

One last thing to keep in mind that can be confusing when first using Servlets, JSPs and Web Applications; you need to determine what version of the Servlet/JSP specification your web hosting company supports. THe most current version is the Servlet 2.4/JSP 2.0 specification, but some hosting companies still only support the Servlet 2.3/JSP 1.2 Specification. There are some major differences between the two. I would recommend using on your desktop the version of TomCat that matches the same specification that your web hosting company uses. Tomcat v5.x is Servlet-2.4/JSP-2.0 compliant, Tomcat v4.x is Servlet2.3/JSP-1.2 compliant, and Tomcat v3.x is Servlet-2.2/JSP-1.1 compliant.

This all may be more information then you wanted or need at this time, but I think it is best that you at least get a basic awareness, and perhaps understanding of Web Applications as you move forward. Even simple websites can benefit for them. Nonetheless, if are only deploying a very basic site, you may be able to move forward without them. A lot of that, however, is going to depend on what your hosting company supports and allows. Since I work with and deploy web applications on dedicated servers under my control at my employer, I cannot speak well to the issues you may face with a hosting company.

I hope that helps...
[ March 15, 2005: Message edited by: Mark Vedder ]
ramakrishna madati
Greenhorn

Joined: Mar 15, 2005
Posts: 9
Thankyou Mark..

I understand there is a learning curve for me in this regard. I have got Core Servlets and JavaServer Pages book and iam on it..

Thanx a lot.
ramakrishna madati
Greenhorn

Joined: Mar 15, 2005
Posts: 9
Originally posted by ramakrishna madati:
Hello all,

firstly very good place for me to land in.

Iam working on a website. My host has given me details of where to put my jsp files. Its something like myservlets/jsp under my domain..

1] i have to use www.mydomain.com/myservlets/jsp/some.jsp to invoke my jsp. But i want to use only www.mydomain.com/some.jsp only. How do i do it?


[ March 15, 2005: Message edited by: Bear Bibeault ]


My host is unable to do it for me till now..
can there be any problem to edit web.xml if iam using virtual hosting.
can anybody give their inputs in this regard. My host still is using tomcat4 only.

Can anybody explain what is happening in this URL example: www.javaranch.com/books.jsp or www.javaranch.com/index.jsp how is the URL mapping done here.. what coult be the code added to web.xml to acheive this..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 404 error redirecting