| Author |
Classpath problem.
|
Andrew Broussard
Greenhorn
Joined: Mar 10, 2006
Posts: 17
|
|
Hi, I have the following entries in my enviornment variables. "JAVA_HOME" value= "c:\j2sdk1.4.2_11" "PATH" value= "c:\j2sdk1.4.2_11\bin" for Java. For servlets, "Servlet CLASSPATH" value="C: \Tomcat5.5\common\lib\servlet-api.jar" And now I want to compile a small servlet application with following three classes.My problem is that i don't know where to put the files and do I have to make further changes to class path.I have tried hard but without success.Thanks alot guys,please help me out,regards Andrew here are the three classes and web.xml file. package com.example; import javax.servlet.*; public class MyServletContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { ServletContext sc=event.getServletContext(); String dogBreed=sc.getServletContext("breed"); Dog d=new Dog(dogBreed); sc.setAttribute("dog",d); } public void contextDestroyed(ServletContextEvent event) { } } package com.example; public class Dog { private String breed; public Dog(String breed) { this.breed; } public String getBreed() { return breed; } } package com.example; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class ListenerTester extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out=response.getWriter(); out.println("test context attributes set by listener<br>"); out.println("<br>"); Dog dog=(Dog) getServletContext().getAttribute("dog"); out.println("Dog's breed is: " + dog.getBreed()); } } web.xml <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com.xml/ns/j2ee/web-app_2_4.xsd" version="2.4" <servlet> <servlet-name>ListenerTester</servlet-class> <servlet-class>com.example.ListenerTester</servlet-class> </servlet> <servlet-mapping> <servlet-name>ListenerTester</servlet-name> <url-pattern>/ListenerTest.do</url-pattern> </servlet-mapping> <context-param> <param-name>breed</param-name> <param-value>Great Dane</param-value> </context-param> <listener> <listener-class> com.example.MyServletContextListener </listener-class> </listener> </web-app>
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
Originally posted by Andrew Broussard: I have the following entries in my enviornment variables. "JAVA_HOME" value= "c:\j2sdk1.4.2_11" "PATH" value= "c:\j2sdk1.4.2_11\bin" for Java. For servlets, "Servlet CLASSPATH" value="C: \Tomcat5.5\common\lib\servlet-api.jar" And now I want to compile a small servlet application with following three classes.My problem is that i don't know where to put the files and do I have to make further changes to class path.I have tried hard but without success.Thanks alot guys,please help me out,regards Andrew
Have you compiled a "HelloWorld" plain old java application yet? It sounds like you're trying to jump into the deep water before learning to float. I'm not familiar with "Servlet CLASSPATH". How does it relate to your (already existing?) CLASSPATH?
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Andrew Broussard
Greenhorn
Joined: Mar 10, 2006
Posts: 17
|
|
|
I have successfully done that helloWorld and alot of plain java programs.My problem is how we need to adjust the class path variables for servlets and where to keep the different files of servlet code.Thankyou.
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
|
If you are saying that you need different classpaths when compiling different projects, then don't use the CLASSPATH environment variable. Instead use the -classpath option of javac.
|
Joanne
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Normally, you don't worry at all about the CLASSPATH for servlets. Or, rather, that CLASSPATH is dependent on the Server. A web application is usually stored in a WAR, but the exploded structure is the same: /WEB-INF/classes/<This is where your classes go> /WEB-INF/lib/<This is where your .jar files go> Search for WAR files for examples.
|
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
I think this thread will feel more at home in the Tomcat forum...
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
 |
|
|
subject: Classpath problem.
|
|
|