Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to Write a web.xml for a JSP

ilarumilarum Member Posts: 28
Hi,
I have locally installed tomcat on my machine. I created a folder called "simple" under the "webapps " directory of my Tomcat installation. under simple I have the following directory structure.

simple
jsp (constains a simplJSP.jsp)
images (empty)
WEB-INF
--classes (directory empty for now)

I have worked with servlets, now for this JSP how should my web.xml be written. Could anybody say me how should I write the web.xml file.

Contents of SimpleJSP.jsp

<%@ page import="java.util.Date" %>


The current time is <% = new Date().toString(); %>




Comments

  • fzammettifzammetti Member Posts: 68
    You don't need to do anything special in web.xml for JSP's. So, take any of the sample app's web.xml and remove just about everything, and your good to go. web.xml describes your webapp as a whole, and as such must be present. And while it does have some tags associated with JSP's, none of them are required to use JSP's. Nor is anything required in it to use servlets by the way. Actually, to save you the time, this is all that you should really have to have in web.xml:

    [code]
    <?xml version="1.0"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">


    [/code]

    That should do it. You should then be able to access your JSP's, no problem. I might actually be wrong about servlets, but if I remember correctly, you can just specify the class in the URL to execute them. Don't hold me to that though :)

    : Hi,
    : I have locally installed tomcat on my machine. I created a folder called "simple" under the "webapps " directory of my Tomcat installation. under simple I have the following directory structure.
    :
    : simple
    : jsp (constains a simplJSP.jsp)
    : images (empty)
    : WEB-INF
    : --classes (directory empty for now)
    :
    : I have worked with servlets, now for this JSP how should my web.xml be written. Could anybody say me how should I write the web.xml file.
    :
    : Contents of SimpleJSP.jsp
    :
    : <%@ page import="java.util.Date" %>
    :
    :
    : The current time is <% = new Date().toString(); %>
    :
    :
    :
    :
    :

Sign In or Register to comment.