File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes How do I get a .jsp page in a subdirectory served as the first page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How do I get a .jsp page in a subdirectory served as the first page?" Watch "How do I get a .jsp page in a subdirectory served as the first page?" New topic
Author

How do I get a .jsp page in a subdirectory served as the first page?

Clifford Wirt
Greenhorn

Joined: Mar 03, 2013
Posts: 2
Tomcat Version: 7.0.35

Given this directory structure under CATALINA_HOME/webapps/ on my local machine:

REAL_SIMPLE_TEST
* WebContent
**REAL_SIMPLE_TEST_HOME.jsp

**styles
***Stylesheet.css


* WEB_INF
** web.xml


How do I get REAL_SIMPLE_TEST_HOME.jsp served as the first page when in the browser I hit: http://localhost:8080/REAL_SIMPLE_TEST/ ? Placing

<welcome-file-list>
<welcome-file>/WebContent/index.jsp</welcome-file>
</welcome-file-list>

in the web.xml is not working.

(The reason I am asking this question: Some years ago I built a web application hosted by Webappcabaret using basically this structure. The people at Webappcabaret tweaked something or other and got this to work. Now I have to move my application out of Webappcabaret into a new host. But when I get all the files into a .war file and put it in the webapps directory of the Tomcat7 on my local machine, the homepage no longer gets served as the first page. Also, Tomcat no longer recognizes the style sheet placed in the subdirectory. I am trying to get these issues resolved on my local machine before placing the web application in a new host.)


Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Greetings Clifford Wirt ,

Firstly you have to understand the directory structure of a web application and how it gets deployed as war on tomcat. The important thing to understand is that the WebContent folder is the root of your project hierarchy and all references made to subfolders inside webcontent are to be referenced from root. So if you REAL_SIMPLE_TEST_HOME.jsp is located directly inside the WebContent folder, then you have to put the following entry in your web.xml


Similarly for your styles folder, refer it to as /styles/Stylesheet.css

Do post back for any further queries


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Clifford Wirt
Greenhorn

Joined: Mar 03, 2013
Posts: 2
Unfortunately, this does not work:



I get an Apache Tomcat Status 404 error.

I should mention that RealSimpleTest is under the webapps directory. Tomcat seems to interpret the '/' as meaning 'webapps/RealSimpleTest'. But I need the first page served to be uner webapps/RealSimpleTest/WebContent instead.
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Try removing the forward slash from the path of the JSP . Its at the root of the project , so it should have worked . ( always works for me ) . Anyhow try to remove the "/" from the path and change it to "REAL_SIMPLE_TEST_HOME.jsp"
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

I suspect that you are depending on your IDE to deploy the web application. Depending on the IDE and plugins involved, it's most likely that "/WebContent" is actually something like the root of the WAR that the IDE assembles into. Thus, the true resource path within the webapp would be "/index.jsp".


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I get a .jsp page in a subdirectory served as the first page?
 
Similar Threads
TC can't find my projects html
My *.jsp files will not execute unless in /servlet path.
Tomcat - Apache connector problem
determine if file or directory in a web application
Tomcat Web App - Strange issue. Requires 2 restart for SSO mode to work