Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Problem deploying WAR file

Problem deploying WAR file  Posted: Mar 5, 2003 11:36 PM   Reply  
 
Hey guys, i'm really new to this servlet stuff and need a bit of help. I wrote a simple helloworld servlet below but it won't display. Below is a detailed account of what is in each of my files and the location of each file.
NOTE:I then followed Tomcat installation tutorial at http://www.massless.org/Default.asp?article=1 pretty close!

Now, my TOMCAT root is at:
C:\Tomcat 4.1\

I created the war file (test.war) no problem and put it in the
{TOMCAT root}\webapps

Tried to access my page at: http://localhost:8080/test/HelloWorldServlet
and I got the following error:

----------------------------------------------------------------
TOMCAT ERROR
----------------------------------------------------------------
HTTP Status 404 - /test/HelloWorldServlet
type Status report
message /test/HelloWorldServlet
description The requested resource (/test/HelloWorldServlet) is not available.

----------------------------------------------------------------
SE RVER.XML
----------------------------------------------------------------
Then I added the following entry into server.xml ABOVE the other context path item in the file:
<Context path="/test" docBase="webapps/test" crossContext="false" debug="0" reloadable="true"/>

------------------------------------------------------- ---------
WEB.XML
-------------------------------------------------------------- --
I then added the following entry into my web.xml file and stuck it in
C:\Tomcat 4.1\webapps\test\WEB-INF:
<web-app>
<display-name>Hello World!</display-name>
<session-timeout>30</session-timeout>
& lt;servlet>
<servlet-name>Hello World Servlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet -class>
<load-on-startup>1</load-on-startup>
<init-param>
& lt;param-name>name</param-name>
<param-value>value</param-valu e>
</init-param>
</servlet>
</web-app>

------------------- ---------------------------------------------
HELLOWORLDSERVET.JAVA
------------ ----------------------------------------------------
//Import Servlet libraries
import javax.servlet.*;
import javax.servlet.http.*;
//Import Java libraries
import java.io.*;
public class HelloWorldServlet extends HttpServlet
{
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1& gt;Hello World!</h1>");
out.println("</body>");
out.println("</html>") ;
out.close();
}
}  
0
KABOOM
Asked:
KABOOM
1 Solution
 
richiegrCommented:
Hi

If you use Tomcat > 4 then you don't need to make any change to the server.xml file you have just (better) to stop tomcat then only copy you war file under /webapps dir

If you war file if correct Tomcat extract the file under webapps dir so if you war filename is test.war you'll have:
this dir :
C:\Tomcat 4.1\webapps\test

To access your servlet or jsp page use the url:
http://localhost:8080/test

if you have configured a default page like index.jsp or default.html you should see it

Bye
0
 
NetWizeCommented:
and for your servlet to work you need a

<servlet-mapping>
  <servlet-name>Hello World Servlet</servlet-name>
  <url-pattern>/HelloWorldServlet</url-pattern>
</servlet-mapping>
0
 
rrzCommented:
I agree with NetWize.
Also look at the DTD for a web.xml. You don't have order correct.
0
 
kennethxuCommented:
>> <Context path="/test" docBase="webapps/test" crossContext="false" debug="0" reloadable="true"/>

this is wrong, should be docBase="test"

also, you need the mapping as NetWize suggested in your web.xml

it is recommended that you always have an html file in your war. and try to access the html file first, that ensures you app is installed without problem, then try servlets.
0
 
myuenCommented:
I think NetWize is right but I totally had the same problem and i'll tell you what did the trick for me:

In your web.xml:

REPLACE:
<servlet-name>Hello World Servlet</servlet-name>

WITH:
** NOTICE that there are no spaces in between.  I'm not quite sure why this made a difference for me b/c it's just a name - but it does.
<servlet-name>HelloWorldServlet</servlet-name>

Try it!
Let me know how it turns out.
Later dude.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now