Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Browser won't show url. Web.xml

 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can you please help me. Java, servlets, tomcat...


So, I have servlets and my browser says;

"Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later."

my url is

...tomcat/me/mything/servlet/MovieServlet

but a browser shows ...tomcat/steve/mything, no problem there.

But I think this web.xml is not correct, what is wrong? ;

 
Ramasamy Anbalagan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You have written <servlet-mapping> on web.xml. when you giving url, it matches on url-pattern on servlet-mappting, then call corresponding servlet. You have mentioned servlet name as "invoker" on servlet mapping, but there is no one servlet in the name of invoker in web.xml

 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thanks! Indeed, I removed invoker. And now web.xml is like;



And now a browser says;




What on earth is still wrong?
 
Ramasamy Anbalagan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please give correct path of servlet class that where you have wrriten. Error code says, couldn't find servlet class loaction.




<servlet-class>MovieServlet</servlet-class>
 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that must be it!!

But I tried path tomcat/me/mything/servlet/MovieServlet;




and I tried



but a same result from a browser. What is still wrong?
 
Charles 'King
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is incorrect:



Please create a conventional package for your class, e.g.:



Doing this will prevent conflicts with other container resources, etc...

If you don't understand how to create packages, go here: http://java.sun.com/docs/books/tutorial/java/package/packages.html
 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thanks.

Well, I did a package earlier and that didn't work. So I don't want to do that again.
Browser showed url before and classes were not in a package, so package isn't necessary.
But thank you for that advice, too!

But what about that path



should it be:




well, same result with that. I'm so frustrated. This will ever again work, that's how I feel.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
james smitho wrote:Well, I did a package earlier and that didn't work. So I don't want to do that again.

Then you will never, ever, get it to work. Ever.

Servlet classes must be in a package. The class declaration must identify that package. The mapping must identify the servlet.

Anything else is a complete waste of time.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

This tells me that you've hosed your Tomcat installation. Have you removed any jar files?
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,

I think you are confusing Java packages with URLs. These are different.
When you create your Servlet class, that class (with a .java source file) needs to be defined in a Java package other than the default (no package). This means that in the beginning of the source file, you need to include a package line like:

Then, in the web.xml file, your <servlet-class> element would be

 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you all! Great answers. Well, there are not .jar anywhere in tomcat/

all right, a package is necessary. But indeed, in the autumn, I had two servlets
and my browser opened them ( both url's worked ) and they weren't in a package.


now a browser shows ...tomcat/steve/mything
but NOT servlets.

so, in every class I will type a ( for example ) code:




and I do a folder and name it "testing" and put it in
WEB-INF/classes
And inside that folder I will
put all classes, .java-files and build.xml.

and in the web.xml file, <servlet-class> would be




and a mapping would be;

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
james smitho wrote:Well, there are not .jar anywhere in tomcat/

If so, your Tomcat is hosed and nothing will ever work.

If Tomcat 5, you should have a bunch of jars in the common/lib and server/lib folders.

If Tomcat 6, you should have a bunch of jars in the lib folder.

If not, what happened to them?

You'll need to set up Tomcat again. Without a valid installation, there is no hope.

all right, a package is necessary. But indeed, in the autumn, I had two servlets
and my browser opened them ( both url's worked ) and they weren't in a package.

Sometimes it will work; most often it will not. Are you a gambling man?
 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. Sounds critical... Well, Tomcat is 5.5...
So I should have a bunch of jars in the common/lib and server/lib folders.

What .jars? I don't know, maybe I deleted them by accident.

So I will delete tomcat and after that type in sql "setup tomcat" ?


No, gambling is not good. I want to get this work.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you're having a hard time getting the basics down. May I please recommend a set of tutorials which may be of help to you? Please have a look at http://courses.coreservlets.com/Course-Materials/csajsp2.html That page has lots of great links. Also, see the following URL: http://pdf.coreservlets.com/ This provides access to chapters of the book Core Servlets and JavaServer Pages, Second Edition for free download in PDF format.

Best Regards,
 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thank you for your answers! I think these are ( tomcat 5.5... ) what I need;

in common/lib

these files;

commons-el.jar
jasper-compiler.jar
jasper-compiler.jdt.jar
jasper-runtime.jar
jsp-api.jar
naming-factory.jar
naming-factory-dbcp.jar
naming-resources.jar
servlet-api.jar

in server/lib

these files;

catalina.jar
catalina-ant.jar
catalina-ant-jmx.jar
catalina-cluster.jar
catalina-optional.jar
catalina-storeconfig.jar
commons-modeler.jar
servlets-cgi.renametojar
servlets-default.jar
servlets-invoker.jar
servlets-ssi.renametojar
servlets-webdav.jar
tomcat-ajp.jar
tomcat-apr.jar
tomcat-coyote.jar
tomcat-http.jar
tomcat-jkstatus-ant.jar
tomcat-util.jar


So, can I just put these files and see what my browser says? Or what else will I have to do?
 
veeresh soni
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think problem is in your web xml i have mention place where the problem . check out if this change will work or not.

# # <?xml version="1.0" encoding="ISO-8859-1"?>
# # <!--<!DOCTYPE web-app
# # PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
# # "http://java.sun.com/dtd/web-app_2_3.dtd"> -->
# #
# # <web-app>
# #
# # <display-name>
# # The name of the application
# # </display-name>
# # <description>
# # Servlet
# # </description>
# #
# # <context-param>
# # <param-name>name_of_context_initialization_parameter</param-name>
# # <param-value>value_of_context_initializtion_parameter</param-value>
# # <description> Servlet </description>
# # </context-param>
# #
# # <servlet>
# # <servlet-name>MovieServlet</servlet-name>
# # <description>Servlet</description>
# # <servlet-class>MovieServlet</servlet-class>
# # <init-param>
# # <param-name>foo</param-name>
# # <param-value>bar</param-value>
# # </init-param>
# # </servlet>
# #
# # <servlet> // Change is here you have not started the servlet tag and you need to provide mappng also for the same
# # <servlet-name>MovieServletB</servlet-name>
# # <servlet-class>MovieServletB</servlet-class>
# # </servlet>
# #
# #
# # <servlet-mapping>
# # <servlet-name>MovieServlet</servlet-name>
# # <url-pattern>/servlet/*</url-pattern>
# # </servlet-mapping>
# #
# #
# # <session-config>
# # <session-timeout>30</session-timeout>
# # </session-config>
# #
# # </web-app>
 
james smitho
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Here's everything that I can now think about this whole thing.

I thought that this massive all.zip ( and I have put it in WEB-INF/lib )
would be enough. It contains the following;

three folders;

- javax/sql, which has many .class- files
- META-INF, which has MANIFEST.MF
- oracle, this folder has many folders;
core
jdbc
jpub
net
security
sql

And all those 6 folders contain something, I can list
them later, if it helps. I don't have folders;
common/lib and server/lib.

I think that this all.zip covers those .jars,
and this all.zip is all what I need. ??


This is my whole path that I can/am allowed use;

/home/me/tomcat/webapps/mything/WEB-INF/ and inside
WEB-INF there are four folders;

classes ( this contains .class- files, .java- files and build.xml )
lib ( this contains that all.zip )
src ( empty )
web.xml



and
I added that line in web.xml ( but I haven't made a package yet! ) and it is now like this;



but browser said same thing, so there were no changes. Thanks anyway.


But I believe you and I will have to do that package;


So, in every class I will type a ( for example ) code:




and I do a folder and name it "testing" and put it in
WEB-INF/classes

and then web.xml would be like this;



Are there still errors or are these finally correct?

If I make all these changes, maybe
it isn't necessary to set up Tomcat again?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic