installation problem

I am totally new to JSP. I am trying to run some jsp code and seem to be having problems running it. I had quite a few questions in this regard and would really appreciate some help.For the environment details:

Apache Tomcat 5.0.28 (it seems Tomcat 5.5 could lead to some issues, not sure if its correct).

JDK 1.5.0_11

JRE 1.5.0_11

Eclipse-SDK-3.2.2-win32

Eclipse Tomcat Plugin V32 beta 2 (from Sysdeo)

1) While creating a new Tomcat Project firstly, it does not put a new file in the default package under WEB-INF/src, in fact I dont see the default package. How could I create it?

2) In eclipse what should I set the defalut JRE to? Could someone be specific about the path for this please.

2) Even though I delete projects and refresh it, I can't seem to get rid of the old projects

3) After starting Tomcat, got an error, unable to compile class for JSP, unable to find javac compiler. However, I did go to the control panel and set the path, it still does not work.

Too many queries in a single posting, but have a project submission and so the urgency.

[1126 byte] By [m_minia] at [2007-11-26 21:22:31]
# 1

It's better to not use an IDE if you are new to Tomcat and JSPs and web development, that way you'll understand the concepts clearly.

To set-up a web application

1) first install JDK - (latest version is better) , then set JAVA_HOME to the JDK's root folder for example C:\dev\jdk - JAVA_HOME is your system envrionment variable.

2) Then install Tomcat (latest version is better) 5.5 or 6.x , then set CATALINA_HOME to Tomcat's root folder for example C:\dev\tomcat

3) Tomcat's lib folder will have servlet-api.jar - this is the Servlet 2.4 or Serlvet 2.5 API , and jsp-something.jar - this is either JSP 2.0 or JSP 2.1

Set the Eclipse library to point to these JAR files.

4) Add the JDK bin and Tomcat bin to the System PATH variable , for example %JAVA_HOME%/bin;%TOMCAT_HOME%/bin

By adding the bin folders to the PATH you can call javac compiler and java commands from anywhere on the command line.

Also, you'll be able to call Tomcat's startup and shutdown batch files from anywhere on the command line.

Once you have the above set-up , start Tomcat with startup.bat

Then you'll be able to see the default application at http://localhost:8080/ , After you're done with Tomcat , shut it down with shutdown.bat

Instead of JRE , use JDK - its better to use JDK.

Anyway, here are the answers to some of your questions:

1) Your source files don't need to be under WEB-INF/src , they can be anywhere . But your class files should be under WEB-INF/classes/

You can use Ant script to compile the source Java files into the classes folder, or use the compile feature of Eclipse.

2) Your JDK path is the folder on which you installed it. The main folder, for example C:\dev\jdk

3) Tomcat looks for JAVA_HOME , to compile JSP files into servlet class files, if you don't set JAVA_HOME correctly, Tomcat wont work.

appy77a at 2007-7-10 3:02:03 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for the suggestion. I am constrained to use Eclipse, cant do away with it. I took some pointers from your solution. This time the error washttp status 404, requested resource is not avaliable.Any suggestions?
m_minia at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
If you have to use Eclipse use Eclipse WTP -- Web tools Platform it will have mush more support for web programmingdid you add your servlet name to web.xml?it would be better if you can provide some more info on what you have done
arunmp25a at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

under WEB-INF/src is the file called SimpleServlet.java, code for that being:

import java.io.PrintWriter;

import javax.servlet.*;

public class SimpleServlet extends javax.servlet.http.HttpServlet{

public void doGet(javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws javax.servlet.ServletException, java.io.IOException{

performTask(request, response);

}

public void doPost(javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

throws javax.servlet.ServletException, java.io.IOException{

performTask(request, response);

}

public void performTask(javax.servlet.http.HttpServletRequest request,

javax.servlet.http.HttpServletResponse response)

{

try

{

response.setContentType("text/html");

PrintWriter out=response.getWriter();

out.println("This is the DEMO");

}

catch(Throwable theException)

{

theException.printStackTrace();

}}}

Under Web-INF is the file called web.xml, code for that being:

<?xml version="1.0" encoding="UTF-8" ?>

<web-app>

<servlet>

<servlet-name>SimpleServlet</servlet-name>

<servlet-class>SimpleServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>SimpleServlet</servlet-name>

<url-pattern>/SimpleServlet</url-pattern>

</servlet-mapping>

</web-app>

On running Tomcat, get the screen:

Mar 13, 2007 12:07:45 PM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Mar 13, 2007 12:07:45 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 609 ms

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/5.0.28

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardHost start

INFO: XML validation disabled

Mar 13, 2007 12:07:46 PM org.apache.commons.digester.Digester fatalError

SEVERE: Parse Fatal Error at line 1 column 1: Content is not allowed in prolog.

org.xml.sax.SAXParseException: Content is not allowed in prolog.

at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)

at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)

at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)

at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)

at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)

at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

at org.apache.commons.digester.Digester.parse(Digester.java:1548)

at org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)

at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)

at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)

at org.apache.catalina.core.StandardService.start(StandardService.java:480)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)

at org.apache.catalina.startup.Catalina.start(Catalina.java:556)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

Mar 13, 2007 12:07:46 PM org.apache.catalina.startup.ContextConfig applicationConfig

SEVERE: Parse error in application web.xml

org.xml.sax.SAXParseException: Content is not allowed in prolog.

at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

at org.apache.commons.digester.Digester.parse(Digester.java:1548)

at org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)

at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)

at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)

at org.apache.catalina.core.StandardService.start(StandardService.java:480)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)

at org.apache.catalina.startup.Catalina.start(Catalina.java:556)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

Mar 13, 2007 12:07:46 PM org.apache.catalina.startup.ContextConfig applicationConfig

SEVERE: Occurred at line 1 column 1

Mar 13, 2007 12:07:46 PM org.apache.catalina.startup.ContextConfig start

SEVERE: Marking this application unavailable due to previous error(s)

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardContext start

SEVERE: Error getConfigured

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardContext start

SEVERE: Context startup failed due to previous errors

Mar 13, 2007 12:07:46 PM org.apache.catalina.startup.ContextConfig applicationConfig

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatProject]

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardHost getDeployer

INFO: Create Host deployer for direct deployment ( non-jmx )

Mar 13, 2007 12:07:46 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\admin.xml

Mar 13, 2007 12:07:46 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true

Mar 13, 2007 12:07:46 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true

Mar 13, 2007 12:07:46 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', returnNull=true

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\balancer.xml

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\manager.xml

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /jsp-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\jsp-examples

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /servlets-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\servlets-examples

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /tomcat-docs from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\tomcat-docs

Mar 13, 2007 12:07:47 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /webdav from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\webdav

Mar 13, 2007 12:07:47 PM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Mar 13, 2007 12:07:47 PM org.apache.jk.common.ChannelSocket init

INFO: JK2: ajp13 listening on /0.0.0.0:8009

Mar 13, 2007 12:07:47 PM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=15/16 config=C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\jk2.properties

Mar 13, 2007 12:07:47 PM org.apache.catalina.startup.Catalina start

INFO: Server startup in 1735 ms

On entering

http://localhost:8080/Servlet1/SimpleServlet

in the browser get the error message

The requested resource (/Servlet1/SimpleServlet) is not available.

Any suggestions please?

m_minia at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

If you're getting this error:

org.xml.sax.SAXParseException: Content is not allowed in prolog.

then it means that there is either a white space, some other character or an invisible hex character (known as BOM - Byte Order Mark) immediately before the XML prolog

<?xml version="1.0" ?>

The invisible character is normally not visible in a regular text based editor.

You'll need a Hex editor to view the BOM - search on Google for Cygnus hex editor - its free, then see if it shows any characters before <? in web.xml

Delete those characters and re-try.

appy77a at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thanks for your input. Now on starting Tomcat, I get:

Mar 13, 2007 12:44:56 PM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Mar 13, 2007 12:44:56 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 563 ms

Mar 13, 2007 12:44:56 PM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Mar 13, 2007 12:44:56 PM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/5.0.28

Mar 13, 2007 12:44:56 PM org.apache.catalina.core.StandardHost start

INFO: XML validation disabled

Mar 13, 2007 12:44:56 PM org.apache.catalina.startup.ContextConfig applicationConfig

INFO: Missing application web.xml, using defaults only StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TomcatProject]

Mar 13, 2007 12:44:56 PM org.apache.catalina.core.StandardHost getDeployer

INFO: Create Host deployer for direct deployment ( non-jmx )

Mar 13, 2007 12:44:56 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\admin.xml

Mar 13, 2007 12:44:57 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true

Mar 13, 2007 12:44:57 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true

Mar 13, 2007 12:44:57 PM org.apache.struts.util.PropertyMessageResources <init>

INFO: Initializing, config='org.apache.webapp.admin.ApplicationResources', returnNull=true

Mar 13, 2007 12:44:57 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\balancer.xml

Mar 13, 2007 12:44:57 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Processing Context configuration file URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\Catalina\localhost\manager.xml

Mar 13, 2007 12:44:58 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /jsp-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\jsp-examples

Mar 13, 2007 12:44:58 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT

Mar 13, 2007 12:44:58 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /servlets-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\servlets-examples

Mar 13, 2007 12:44:58 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /tomcat-docs from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\tomcat-docs

Mar 13, 2007 12:44:58 PM org.apache.catalina.core.StandardHostDeployer install

INFO: Installing web application at context path /webdav from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\webdav

Mar 13, 2007 12:44:58 PM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Mar 13, 2007 12:44:58 PM org.apache.jk.common.ChannelSocket init

INFO: JK2: ajp13 listening on /0.0.0.0:8009

Mar 13, 2007 12:44:58 PM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/31 config=C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\jk2.properties

Mar 13, 2007 12:44:58 PM org.apache.catalina.startup.Catalina start

INFO: Server startup in 1844 ms

Does it look fine now or do I need to do something about it? The error message remains the same.

m_minia at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I assume the above output is on Tomcat's console?

I don't see any error message in the above post.

INFO means , it's just informational message - not error.

Your Servlet / JSP should work fine (unless there are additional problems), did you test those?

Also the URL you're using is wrong:

http://localhost:8080/Servlet1/SimpleServlet

it should be

http://localhost:8080/SimpleServlet

according to the URL pattern you have specified in web.xml

Message was edited by:

appy77

appy77a at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanks for the suggestion. As far as my knowledge goes, I think http://localhost:8080/Servlet1/SimpleServlet is fine for the url as the naming goes as port number/Project_Name/class_Name. I finally got things to work. I had to unistall Tomcat5.0 and install Tomcat5.5 for this. Looks like it was more of a compatibilty issue, as when I started Tomcat it seemed to complain about the JDK version installed. So the key was to have the correct JDK verison with the right version of Tomcat.

m_minia at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

You didn't specify if Servlet1 was the name of your project, since you now mentioned that it is the project the URL http://localhost:8080/Servlet1/SimpleServlet , should be fine .

It appeared to me that Servlet1 could actually be a Servlet class and not a project and that's why I thought the URL could be incorrect.

FYI in the above example Servlet1 is called a context or /Project_Name/ is the context .

You can also deploy an app at the root context , that is' http://localhost:8080/, no need to add Project_Name , but for this setting the docBase and appBase of the project should point to

C:/Project_Name/

You probably don't need to set up the project at the root context , but it's good to know, that it is possible because most applications in the business world are deployed to the root context.

appy77a at 2007-7-10 3:02:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...