• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

Defining the default JSP

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
carljokl
Asked:
carljokl
  • 7
  • 5
  • 3
  • +1
2 Solutions
 
TimYatesCommented:
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
 
bloodredsunCommented:
   ...
    <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
 
bloodredsunCommented:
Oh, forgot to add, you can use a servlet as a welcome page if you use servlet spec 2.4
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
gksinghietCommented:
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
 
carljoklAuthor Commented:
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
 
bloodredsunCommented:
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
 
carljoklAuthor Commented:
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
 
bloodredsunCommented:
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
 
carljoklAuthor Commented:
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
 
gksinghietCommented:
>>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
 
carljoklAuthor Commented:
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
 
carljoklAuthor Commented:
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
 
bloodredsunCommented:
>>that the default servlet is not defined 404

Sorry what do you mean by "default servlet" ?
0
 
carljoklAuthor Commented:
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
 
gksinghietCommented:
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
 
carljoklAuthor Commented:
That does not apper to have made any difference.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now