[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Defining the default JSP

Posted on 2006-03-29
16
Medium Priority
?
301 Views
Last Modified: 2010-04-01
I am not hugely skilled in using Tomcat and JSP but am an experience Java Developer. I inherited a project which was developed by a former placement student which is a web based documet management system which uses the Strut framework. I worked on some improvements for the first released version of the project which is in use withing the company. It has now been proposed that I go back and add some extra functionality. I have had problems just getting my application to run at all but I am that far along now. I have the problem that the images in the site are not appearing but when I look at the URLs pointed to it seems they are correct and the image files are definately there. I also think the style sheet is not working. I suspect that the folder permissions for the web application are not right but that is only a theory and I am not completely versed in how Tomcat controlls permissions and security and am still learning.

I have created my first web.xml file following the instructions on a web tutorial. I did also have IntelliJ IDEA to check my syntax in the xml file. I was trying to specify the default JSP file to be opened when navigating into the application (hardly rocket science I would have thought but everything is easy when you know how).

My web.xml stands as follows:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <!-- General description of your web application -->
    <icon>
        <small-icon>/jsp/images/logosmall.jpg</small-icon>
        <large-icon>/jsp/images/headlogo.jpg</large-icon>
    </icon>
    <display-name>River</display-name>
    <description>
      River is a web based document management system used for holding important documents
      to be viewd within Rental Result and possibly also by Result's customers.
    </description>
    <context-param>
      <param-name>webmaster</param-name>
      <param-value>Carl.Jokl@rentalresult.com</param-value>
      <description>
        The EMAIL address of the administrator to whom questions
        and comments about this application should be addressed.
      </description>
    </context-param>
    <servlet>
        <servlet-name>default</servlet-name>
        <jsp-file>/jsp/menu.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
      <session-timeout>30</session-timeout>    <!-- 30 minutes -->
    </session-config>
</web-app>

(Be kind it is my first one)

All the JSP's are held in a "jsp" subfolder of the root folder. The images are held in a subfolder of the jsp folder called "images".  The style sheet is held in a sub folder of jsp called "styles". I wonder if the permissions to these folders are being properly set.

I created an ant build script for my project which compiles everything into a convinient war file.

I am running a Tomcat 5.5 server on a Windows 2003 Enterprise server with Ant 1.6.5 and Java EE 1.4 & JSE 1.5.

Thank you for your help.

0
Comment
Question by:carljokl
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 16319254
Does:

        <url-pattern>/index.jsp</url-pattern>

work?

Interesting...  I always did it with a index.jsp in the root directory that does a redirect...

This way (if we get it working) looks much neater ;-)

Tim
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16319275
   ...
    <session-config>
      <session-timeout>30</session-timeout>    <!-- 30 minutes -->
    </session-config>
    <!-- The Usual Welcome File List -->
    <welcome-file-list>
         <welcome-file>index.html</welcome-file>
         <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

This welcome file list will search first for index.html and then index.jsp. As you are using servlet spec 2.3 (says so at the top of the web.xml file) you cannot use a servlet as a welcome file but in that case it's easy to just use a jsp with a redirect if you need to.

You image issue is probably a path issue as the images are loaded realtive to the url so an action called "/myAction.do" will try to load images from the root even though the jsp it references is kept in /jsp/myaction.jsp. You should always use root relative links "/images/myimage.jpg" not page relative ones like "../images/myimage.jpg"
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16319284
Oh, forgot to add, you can use a servlet as a welcome page if you use servlet spec 2.4
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:gksinghiet
ID: 16319330
As you mention that your application is using Struts, so if 'default' is your ActionServlet then the url-pattern should be something like *.do or *.go and not /
Also are you getting 404 error code on requsting the images?
0
 

Author Comment

by:carljokl
ID: 16319549
I have looked at the images and the style sheet usages which are using the full path from the root folder. There is an index.jsp which is supposed to load up first. I may want to try just moving this file to the root and altering any of the links it uses to take it's new position into account. I have no idea why the images are not loading but this is a document management system and trying to retrieve documents is not working either.
0
 
LVL 29

Assisted Solution

by:bloodredsun
bloodredsun earned 100 total points
ID: 16319562
Okay. Your web.xml didn't specify a default landing page/welcome file so that would be why your index page didn't load up first. I would need to be somehting like this

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

As for file permissions, you'll need to check out the CMS you're using and the standard windows permissions.
0
 

Author Comment

by:carljokl
ID: 16319608
Ok progress. I have got the default page loading now. On to the image problems. Would I be showing my ignorance if I have to ask what CMS is?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16319618
My mistake I thought you were using a content management system but you're not, so you don't need to worry :-)

It would just be checking the availabilty of these images. You can do that by trying to directly access them by putting something like this in the browser address bar.

http://localhost:8080/yourapp/images/myimage.jpg 
0
 

Author Comment

by:carljokl
ID: 16319664
This is something I tried when I first saw the problem. I cannot access the images which is why I thought it is a permissions problem. There is a added complexity though if it is a matter of permissions. I am working on the principle that I wrote an ant build script which produces a tidy little war file that I can deploy on tomcat. If I have to alter permissions on the server side of things then I have a problem if the web app folder is continuously deleted and new deployments being created from the war file. I am hoping that tomcat can/does handle the permissions as it would undermine what I am trying to do if I would have to go and alter ther permissions every time I re-deployed the app. I looked at the permissions and did not find anything obviously wrong but didn't want to dig too deep into that untill I knew whether the permissions were actually controlled by Tomcat anyway.
0
 
LVL 5

Expert Comment

by:gksinghiet
ID: 16319804
>>This is something I tried when I first saw the problem
What are you getting as response? an error i suspect with error code 404 or 500?
Check if images are present in the exploded war in work folder.
0
 

Author Comment

by:carljokl
ID: 16319850
I am getting a 404. I get that when trying even to navigate to the jsp folder. I am making some changes to the sharing that is set up to see if it makes a difference because it seems as though things have actually got worse now with none of the other JSPs being reachable. CMS can also stand for Container Managed Security which is the relm stuff which Tomcat uses. I have set up an administrator account with this earlier to allow me to log in to the Tomcat manager.
0
 

Author Comment

by:carljokl
ID: 16319893
To be specific I would say that it is saying that the default servlet is not defined 404 when it tries to load a file.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16319919
>>that the default servlet is not defined 404

Sorry what do you mean by "default servlet" ?
0
 

Author Comment

by:carljokl
ID: 16320007
To be honest I don't know but that is the error. I would guess that Tomcat is looking for something that it cannot find. In the mean time the othe JSP pages are up and running again. I wonder if this could be a strut issue as all the navigation so far is based on Action.do methods and when it comes to the content which is not referenced that way there are problems. This is a fun excercise. This project was developed by a French placement student during last summer. He has gone now and I have inherited it. I have done maintenance on the application but learned all that I needed to in order to do that and not having built this application from scratch I never had a perfect understanding of how it all works.
0
 
LVL 5

Accepted Solution

by:
gksinghiet earned 100 total points
ID: 16322955
I belief it is not a sharing issue. Probably you are thinking in a wrong direction.
For an Struts application you need to deply the ActionServlet as:
<servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
      <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
      </init-param>
      <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
</servlet>
servlet-class could be org.apache.struts.action.ActionServlet or its sub class.
0
 

Author Comment

by:carljokl
ID: 16330017
That does not apper to have made any difference.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question