servlets faq from jguru

1027
Servlets FAQ From jGuru Generated Sep 13, 2005 2:17:14 PM Location: http://www.jguru.com/faq/Servlets Ownership: http://www.jguru.com/misc/user-agree.jsp#ownership . How do I set my CLASSPATH for servlets? Location: http://www.jguru.com/faq/view.jsp?EID=141 Created: Sep 3, 1999 Modified: 2001-05-05 14:19:15.228 Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) That depends. For developing servlets, just make sure that the JAR file containing javax.servlet.* is in your CLASSPATH, and use your normal development tools (javac and so forth). For JSDK: JSDK_HOME/lib/jsdk.jar For Tomcat: TOMCAT_HOME/lib/servlet.jar For running servlets, you need to set the CLASSPATH for your servlet engine. This varies from engine to engine. Each has different rules for how to set the CLASSPATH, which libraries and directories should be included, and which libraries and directories should be excluded. Note: for engines that do dynamic loading of servlets (e.g. JRun, Apache Jserv, Tomcat), the directory containing your servlet class files shoud not be in your CLASSPATH, but should be set in a config file. Otherwise, the servlets may run, but they won't get dynamically reloaded. The Servlets 2.2 spec says that the following should automatically be included by the container, so you shouldn't have to add them to your CLASSPATH manually. (Classloader implementations are notoriously buggy, though, so YMMV.) classes in the webapp/WEB-INF/classes directory JAR files in the webapp/WEB-INF/lib directory This applies to webapps that are present on the filesystem, and to webapps that have been packaged into a WAR file and placed in the container's "webapps" directory. (e.g. TOMCAT_HOME/webapps/myapp.war) The Complete CLASSPATH Guide for Servlets (http://www.meangene.com/java/classpath.html ) by Gene McKenna ([email protected] ) has detailed instructions on how to set your CLASSPATH for JavaWebServer and JRun.

Upload: api-3706318

Post on 13-Nov-2014

117 views

Category:

Documents


2 download

TRANSCRIPT

Servlets FAQ From jGuruGenerated Sep 13, 2005 2:17:14 PMLocation: http://www.jguru.com/faq/Servlets Ownership: http://www.jguru.com/misc/user-agree.jsp#ownership. How do I set my CLASSPATH for servlets? Location: http://www.jguru.com/faq/view.jsp?EID=141 Created: Sep 3, 1999 Modified: 2001-05-05 14:19:15.228 Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) That depends. For developing servlets, just make sure that the JAR file containing javax.servlet.* is in your CLASSPATH, and use your normal development tools (javac and so forth). For JSDK: JSDK_HOME/lib/jsdk.jar For Tomcat: TOMCAT_HOME/lib/servlet.jar

For running servlets, you need to set the CLASSPATH for your servlet engine. This varies from engine to engine. Each has different rules for how to set the CLASSPATH, which libraries and directories should be included, and which libraries and directories should be excluded. Note: for engines that do dynamic loading of servlets (e.g. JRun, Apache Jserv, Tomcat), the directory containing your servlet class files shoud not be in your CLASSPATH, but should be set in a config file. Otherwise, the servlets may run, but they won't get dynamically reloaded. The Servlets 2.2 spec says that the following should automatically be included by the container, so you shouldn't have to add them to your CLASSPATH manually. (Classloader implementations are notoriously buggy, though, so YMMV.) classes in the webapp/WEB-INF/classes directory JAR files in the webapp/WEB-INF/lib directory

This applies to webapps that are present on the filesystem, and to webapps that have been packaged into a WAR file and placed in the container's "webapps" directory. (e.g. TOMCAT_HOME/webapps/myapp.war) The Complete CLASSPATH Guide for Servlets (http://www.meangene.com/java/classpath.html) by Gene McKenna ([email protected]) has detailed instructions on how to set your CLASSPATH for JavaWebServer and JRun. See also http://www.jguru.com/faq/view.jsp?EID=413601 Comments and alternative answers

Important precision : Under Apache (at least with... Author: Denis BUCHER (http://www.jguru.com/guru/viewbio.jsp?EID=7742), Jan 22, 2000

Important precision : Under Apache (at least with jserv under Linux) you SHOULD NOT put this in any system path, as it won't work. You must put the new path into jserv.properties file, that you located maybe into your apache config dir !!! I've found it simpler to just copy the JAR file to... Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7), Jun 15, 2000 I've found it simpler to just copy the JAR file to the extensions directory of your runtime: jre/lib/ext under your JDK directory, as in: c:\jdk1.3\jre\lib\ext If you are using JRun (atleast with v2.3.3), adding... Author: sharad gupta (http://www.jguru.com/guru/viewbio.jsp?EID=100198), Jul 21, 2000 If you are using JRun (atleast with v2.3.3), adding servlet classes in system path won't work. Instead add the path in jsm.properties file. Unfortunately, Jaz' extension solution doesn't work... Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3), Sep 17, 2000 Unfortunately, Jaz' extension solution doesn't work for some JARs, notably XML parsers. I'm not exactly sure why; perhaps it's package name collision. The webapp solution (WEB-INF/lib) is preferred. I would not hesitate to have a static block in one... Author: Aprameya Paduthonse (http://www.jguru.com/guru/viewbio.jsp?EID=4707), Feb 1, 2001 I would not hesitate to have a static block in one of my early loaded servlets to list the environment parametersstatic { Properties envProps = System.getProperties(); System.out.println("__________________________ BEGIN JAVA SETTINGS _______________________________"); for (Enumeration e = envProps.propertyNames() ; e.hasMoreElements() ;) { String prop = (String)e.nextElement(); System.out.println(prop + " : " + envProps.getProperty(prop)); } System.out.println("_____________________________END JAVA SETTINGS _______________________________"); }

view this Author: kumar varma (http://www.jguru.com/guru/viewbio.jsp?EID=1225116), Feb 4, 2005 along with classpath explanation can you please give us details about servletapi.jar,tools.jar,etc.?Is it the "servlets" directory or the "servlet" directory? Location: http://www.jguru.com/faq/view.jsp?EID=142 Created: Sep 3, 1999 Modified: 1999-12-22 11:09:48.603 Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) For Java Web Server: on the file system, it's "servlets" c:\JavaWebServer1.1\servlets\DateServlet.class in a URL path, it's "servlet" http://www.stinky.com/servlet/DateServlet

Other servlet engines have their own conventions. Usually on the file system it's "servlets" and in a URL it's "/servlet" (which is an alias or virtual path). Comments and alternative answers

It depends on your mapping. Virtual path could be ... Author: Roceller Alvarez (http://www.jguru.com/guru/viewbio.jsp?EID=41828), Apr 28, 2000 It depends on your mapping. Virtual path could be different from the real path. Re: It depends on your mapping. Virtual path could be ... Author: Tim Urberg (http://www.jguru.com/guru/viewbio.jsp?EID=510070), Oct 17, 2001 If you have Tomcat the directory will be: TOMCAT_HOME/webapps/ROOT/WEB-INF/classes If you're running JRun it will be: C:\Program Files\Allaire\JRun\servers\default\default-app\WEB-INF\classes I hope that helpsWhy doesn't my servlet work inside a tag? Location: http://www.jguru.com/faq/view.jsp?EID=143 Created: Sep 3, 1999 Modified: 2000-05-21 14:36:17.445 Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3)

If you use your servlet inside an SSI, you must use res.getOutputStream() and not res.getWriter(). Check the server error logs for more details. Comments and alternative answers

Does anyone here have any experience getting