• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet delivery in Tomcat

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created "myServlets" directory in web-apps. My structure is
jakarta-tomcat-3.2.3
---- webapps
------ admin
------ examples
------ myServlets
--------- images
--------- META-INF
--------- WEB-INF
------------web.xml
------------classes
-------------- HelloWorld.class
-------------- HelloWorld.java
------ ROOT
------ test

This gives these paths:
jakarta-tomcat-3.2.3\webapps\myServlets\web.xml
jakarta-tomcat-3.2.3\webapps\myServlets\classes\HelloWorld.class
This is my web.xml file:
<web-app>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> HelloWorld </servlet-name>
<url-pattern> /hello </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>hello</welcome-file>
</welcome-file-list>
<web-app>

I am getting a 404 Not Found when trying to access a servlet in MyServlets directory with this URL:
http://localhost:8080/myServlets/hello
This is the HelloWorld.java code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld 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("<HEAD><TITLE>Hello World</TITLE></head>");
out.println("BODY");
out.println("<BIG>Hello World<?BIG>");
out.println("</BODY></HTML>");
}

/** Creates new HelloWorld */
public HelloWorld() {
}
}

What am I missing?
Thanks for your time.
[This message has been edited by Betty Schwartz (edited September 10, 2001).]
[This message has been edited by Betty Schwartz (edited September 12, 2001).]
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Betty,
I'm using tomcat as well, with a similar setup. This is the path I need to use to invoke the servlet:
http://localhost:8080/examples/servlet/<servlet here>
Keep your class files where they are, and try that. Let me know if you still have trouble.

- Sean
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Betty,
I confused you then i confused myself
<welcome-file-list>
<welcome-file>hello</welcome-file>
</welcome-file-list>
In this part <welcome-file>hello</welcome-file> hello acutally must be an existing file therefore servlet-url will not work.
<welcome-file>index.jsp</welcome-file> this is OK.
Other that that your servlet works fine. I copied your web.xml and HelloWorld servlet. Web.xml is OK except the part explained above. HelloWorld has some html problems but that is not stoping it from working properly.
If you are still getting error, let me know what is the error message showing up on the Tomcat console. That may help...
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even without the welcome file part, it did not work for me. What URL did you use? I would have to write an "index.jsp" for that to work, right? The error message is 404 Not Found.
Not Found (404)
Original request: /myServlets/hello
Not found request: /myServlets/hello
[This message has been edited by Betty Schwartz (edited September 11, 2001).]
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Betty Schwartz:
I have created "myServlets" directory in web-apps. My structure is
jakarta-tomcat-3.2.3
---- webapps
------ admin
------ examples
------ myServlets
--------- images
--------- META-INF
--------- WEB-INF
------------classes
-------------- HelloWorld.class
-------------- HelloWorld.java
------ ROOT
------ test

This gives these paths:
THIS IS NO GOOD
jakarta-tomcat-3.2.3\webapps\myServlets\web.xml
jakarta-tomcat-3.2.3\webapps\myServlets\classes\HelloWorld.class
IT SHOULD LOOK LIKE
jakarta-tomcat-3.2.3\webapps\myServlets\WEB-INF\web.xml
jakarta-tomcat-3.2.3\webapps\myServlets\WEB-INF\classes\HelloWorld.class
- webapps
-- myServlets
--- WEB-INF
---- classes --- HelloWorld.class
---- web.xml
classes and web.xml must be under WEB-INF
all the .class files must correspond to their package structure under classes folder
This gotta be it!!!
This is my web.xml file:
<web-app>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> HelloWorld </servlet-name>
<url-pattern> /hello </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>hello</welcome-file>
</welcome-file-list>
<web-app>

I am getting a 404 Not Found when trying to access a servlet in MyServlets directory with this URL:
http://localhost:8080/myServlets/hello
This is the HelloWorld.java code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld 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("<HEAD><TITLE>Hello World</TITLE></head>");
out.println("BODY");
out.println("<BIG>Hello World<?BIG>");
out.println("</BODY></HTML>");
}

/** Creates new HelloWorld */
public HelloWorld() {
}
}

What am I missing?
Thanks for your time.
[This message has been edited by Betty Schwartz (edited September 10, 2001).]


 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am so sorry, but I have to report that I actually do have my files as you indicate is correct. I inadverdently typed the paths incorrectly. Now what?
Thank you for continuing to care!!! I appreciate it so much. I know I can figure out a lot after this.
Regards,

Betty
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was trying to send you .zip file from my machine to schwarb@novistar.com but this email is not working or if you want to zip me your myServlets directory so i could take look at it, feel free to do it.
mocca_az@hotmail.com
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Betty,
Problem is in your web.xml file. Ending <web-app> tag in your web.xml is not closed. If you run startup.bat, it will open up the console window and give you the following error message. This is the important part of it...
ERROR reading D:\DEV\Tomcat\webapps\bettyServlets\WEB-INF\web.xml
org.xml.sax.SAXParseException: End of entity not allowed; an end tag is missing.
an end tag is missing
You need to close your <web-app> tag in your web.xml
<web-app>
</web-app>
everything else works fine....
check your mail
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I corrected the file which still did not work. Then I used your zip file which also does not work on my installation. I haven't given up yet, but I sure don't know where to go now.
Thanks.
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sure don't know what to tell you anymore...
In situation like this, i'd delete the entire tomcat directory or whatever you have and also clean up the java_home and tomcat_home...
Are you able to run examples that come with tomcat. Once you start tomcat and run http://localhost:8080/ do you get Tomcat welcome page? If you do, you should be able to run sample jsp/servlets.
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you suggesting just to reinstall the server? I can try that. Now when I start and stop tomcat, I get the following message when I execute "tomcat stop" at the command prompt:
C:\jakarta-tomcat\jakarta-tomcat-3.2.3\bin>tomcat stop
CP =
TOMCAT_HOME = c:\jakarta-tomcat\jakarta-tomcat-3.2.3
CLASSPATH = C:\Program Files\PhotoDeluxe HE 3.0\AdobeConnectables;C:.;\forte4j\
evelopment\examples
Inside gotTomcatHome c:\jakarta-tomcat\jakarta-tomcat-3.2.3
Including all jars in c:\jakarta-tomcat\jakarta-tomcat-3.2.3\lib in your CLASSP
TH.
Using CLASSPATH: c:\jakarta-tomcat\jakarta-tomcat-3.2.3\classes;c:\jakarta-tomc
t\jakarta-tomcat-3.2.3\lib\ant.jar;c:\jakarta-tomcat\jakarta-tomcat-3.2.3\lib\j
sper.jar;c:\jakarta-tomcat\jakarta-tomcat-3.2.3\lib\jaxp.jar;c:\jakarta-tomcat\
akarta-tomcat-3.2.3\lib\parser.jar;c:\jakarta-tomcat\jakarta-tomcat-3.2.3\lib\s
rvlet.jar;c:\jakarta-tomcat\jakarta-tomcat-3.2.3\lib\webserver.jar;C:\Program F
les\PhotoDeluxe HE 3.0\AdobeConnectables;C:.;\forte4j\Development\examples;c:\j
k1.3.1\lib\tools.jar
Stop tomcat
ERROR reading c:\jakarta-tomcat\jakarta-tomcat-3.2.3\conf\server.xml
At The content beginning "<-" is not legal markup. Perhaps the "-" (d char
cter should be a letter.
FATAL: configuration error
org.xml.sax.SAXParseException: The content beginning "<-" is not legal markup.
erhaps the "-" (d character should be a letter.
at com.sun.xml.parser.Parser.fatal(Parser.java:2817)
at com.sun.xml.parser.Parser.fatal(Parser.java:2811)
at com.sun.xml.parser.Parser.content(Parser.java:1526)
at com.sun.xml.parser.Parser.maybeElement(Parser.java:1400)
at com.sun.xml.parser.Parser.content(Parser.java:1499)
at com.sun.xml.parser.Parser.maybeElement(Parser.java:1400)
at com.sun.xml.parser.Parser.parseInternal(Parser.java:492)
at com.sun.xml.parser.Parser.parse(Parser.java:284)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:155)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:126)
at org.apache.tomcat.util.xml.XmlMapper.readXml(XmlMapper.java:214)
at org.apache.tomcat.startup.Tomcat.stopTomcat(Tomcat.java:258)
at org.apache.tomcat.startup.Tomcat.execute(Tomcat.java:174)
at org.apache.tomcat.startup.Tomcat.main(Tomcat.java:235)
C:\jakarta-tomcat\jakarta-tomcat-3.2.3\bin>
If I remove the tomcat directory, do I need to make any changes to the Registry?
[This message has been edited by Betty Schwartz (edited September 16, 2001).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will never get anywhere until you can get your web.xml into good parse-able shape.
FATAL: configuration error
org.xml.sax.SAXParseException: The content beginning "<-" is not legal markup.
erhaps the "-" (d character should be a letter.
That error is suspicious - did you perhaps edit web.xml with MS Word? I really like to use a programmer's editior such as UltraEdit-32 so you can see the real hex character values. Concentrate on debugging web.xml
Bill
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
Thanks for taking a look at this. I assume you meant "server.xml" rather than "web.xml" in this case??? I use Notepad for editing my config files. I wonder if I just need to start over. I have been starting and stopping Tomcat without errors for some time. This is a puzzle.
In your opinion, can I edit that line of server.xml and give it a viable effort to get things working or should I start over?
Thank you sincerely,

Betty
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic