Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

run JSP and servlet in TomCat

  Asked By: Harley    Date: Jul 31    Category: Java    Views: 898
  

any buddy can teach me how to deploy the jsp and servlet in
tomcat environment.
because I cannot direct attach the jsp and clasees file the the
folder.

how to setting the web.xml file.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Mamie Wallace     Answered On: Jul 31

The most common deployment for a web  app is using a war. However, if
you wnat to do it manually, you can create a directory tree under the
<tomcat_root>/webapps directory. Under this directory, you need
another directory called WEB-INF(all caps). This is where web.xml is
stored. deploy  your classes under WEB-INF/classes and libraries into
WEB-INF/lib.

The web.xml is not too tricky. It is a basic xml file  with the normal
xml prolog and a DOCTYPE that indicates it is a webapp and a uri to
the dtd. Here is a sample:

<?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>
<display-name>CactusTestRoot</display-name>
<servlet>
<servlet-name>sampleservlet</servlet-name>
<servlet-class>SampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sampleservlet</servlet-name>
<url-pattern>/SampleServlet</url-pattern>
</servlet-mapping>
</web-app>

The servlet  tag defines the servlet class with an alias. The mapping
is the url that specifies the url that will use that servlet. In this
case, it is /SampleServlet. There are quite a few more tags, but this
is a basic web.xml.

A war is all of the above with a manifest in a zip/jar renamed with
the .war extension. tomcat  can auto-deploy wars. Remember, your
web.xml and related classes go under the WEB-INF directory under the
webapp root.

 
Didn't find what you were looking for? Find more on run JSP and servlet in TomCat Or get search suggestion and latest updates.




Tagged: