Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

servlets not running

Status
Not open for further replies.

dexter195

Programmer
Jun 18, 2003
220
EU
hi, im new to tomcat 5. im having problems running servlets.
i can run jsp and html files from the following location

and i can run this over the network, when i substitute my ip address for localhost, without problems.

the class paths are set up propperly as far as i can see but here they are just in case.

***************************
CATALINA_HOME
C:\Tomcat 5.0;
****************************

****************************
CLASSPATH
C:\Tomcat 5.0\common\lib\servlet-api.jar;

C:\Program Files\Java\jdk1.5.0\jre\lib\ext\servlet.jar\;

C:\Tomcat 5.0\webapps\ROOT\WEB-INF\classes;

%CATALINA_HOME%\common\lib\servlet-api.jar;
****************************

****************************
Path
C:\Program Files\Java\jdk1.5.0\jre\lib\ext\servlet.jar;
****************************



here is the web.xml file

Code:
<web-app>
<display-name>A simple Web Application</display-name>
   <servlet>
      <servlet-name>ServletTest</servlet-name>
      <servlet-class>test.ServletTest</servlet-class>
   </servlet>
  
  <welcome-file-list>
    <welcome-file>ServletTest.html</welcome-file>
  </welcome-file-list>
</web-app>

the package is in the WEB-INF/classes/test/ServletTest folder.

This is the ServletTest.java file

Code:
package test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletTest extends HttpServlet
{
	// the doGet() method is overwritten 
	public void doGet(HttpServletRequest httpServReqRequest, HttpServletResponse httpServResResponce) throws ServletException, IOException
	{
		PrintWriter pwOutput = httpServResResponce.getWriter();
		pwOutput.println("Hello World");
		
	}
}

the ServletTest.htm is in the ROOT folder of tomcat 5

Code:
//ServletTest.htm
<HTML>
	<HEAD>
		
		<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		
		<TITLE>
			Untitled Document
		</TITLE>
		
	</HEAD>

	<BODY>
	
		<FORM ACTION="/servlets/test/ServletTest" METHOD="GET">
			<INPUT TYPE="SUBMIT" VALUE="Go....">
		</FORM>
	
	</BODY>
</HTML>

my appologies for this being exreamly long but im at a loss as to why it wont run.

thanks in advance for any help on this.

dexter
 
3 things :

1) Make sure that your ServletTest.class is in this folder :
WEB-INF/classes/test/

2) You need to add a servlet-mapping to your web.xml :

Code:
<web-app>
<display-name>A simple Web Application</display-name>
   <servlet>
      <servlet-name>ServletTest</servlet-name>
      <servlet-class>test.ServletTest</servlet-class>
   </servlet>
   <servlet-mapping>
       <servlet-name>ServletTest</servlet-name>
       <url-pattern>/servlets/ServletTest</url-pattern>
   </servlet-mapping>
  
  <welcome-file-list>
    <welcome-file>ServletTest.html</welcome-file>
  </welcome-file-list>
</web-app>

and change this :

<FORM ACTION="/servlets/test/ServletTest" METHOD="GET">

to :

<FORM ACTION="/servlets/ServletTest" METHOD="GET">

The URL that you hit the servlet with directly maps to the <url-pattern> in your web.xml

Good luck !



--------------------------------------------------
Free Database Connection Pooling Software
 
cheers again sedj,

i got them working last nite by putting in the servlet-mapping, but didnt have time to put a post saying that (so my appoligies for wasting your time, but at least someone else may benifit).
i was wondering if you could help me with this part though.

im trying to get them to run in a different folder.

e.g. %TOMCAT%\ROOT\NewFolder\

instead of running the application from
%TOMCAT%\ROOT\

im running my html file from this location

i have my WEB-INF folder with the web.xml and the classes and the lib folder in it.

however when i run the servlet from my html file it seems to jump out of this folder and back into the ROOT folder and looks for the servlet in the WEB-INF foder there although i havnt specified this anywhere. do i need to insert a new host of some kind in the server.xml???

oh ye in the above code you have for the web.xml file, i found that if i left the
/servlets/ in it wouldnt work and i also have the servlets running outside of a package (im running Tomcat 5.0.28) i was told in many places you couldnt do this but i tried it out and you can.

Code:
   <!-- Servlet definitions -->
   <servlet>

      <servlet-name>ServletTest</servlet-name>
      <servlet-class>ServletTest</servlet-class>
           
	</servlet>

   <!-- Servlet mappings -->
   <servlet-mapping>
      <servlet-name>ServletTest</servlet-name>
      <url-pattern>ServletTest</url-pattern>
   </servlet-mapping>

thanks again for your help

dexter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top