• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Error instantiating the servlet class  RSS feed

 
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I boque on a simple servlet that I can not invoke, with appal of a JSP page. I have tried everything :
- parameters of the web.xml
- JSP

here is my code:

1/ servlet


2/ Web.xml



3/ my JSP



Error 500

 
Saloon Keeper
Posts: 5288
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

java.lang.ClassNotFoundException: webcart.WebCartServlet


In which directory is the WebCartServlet.class file?
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in /src/webcart/WebCartServlet
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be a language error:
1 / us
2 / fr
 
Marshal
Posts: 67241
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:in /src/webcart/WebCartServlet


The .class file is in the source folder?
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, in the package webcart
 
Rancher
Posts: 3931
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you deploy this to Tomcat, what folder is the .class file in?
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eclipse == /src/webcart/WebCartServlet.class
 
Tim Moores
Saloon Keeper
Posts: 5288
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:no, in the package webcart


Well, "src" is clearly a source directory, is it not?

Regardless, the class file needs to be inside WEB-INF/classes/webcart; is that where it is? Or is it in a jar file that contains all your classes? If so, that would go into WEB-INF/lib
 
Dave Tolls
Rancher
Posts: 3931
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Philippe Ponceblanc wrote:eclipse == /src/webcart/WebCartServlet.class



That's not Tomcat.
That's your IDE.

How are you deploying your web application to Tomcat?
Also, what Tomcat is it?  Is it embedded as part of Eclipse or standalone?
 
Saloon Keeper
Posts: 20510
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Philippe Ponceblanc wrote:eclipse == /src/webcart/WebCartServlet.class



That's not Tomcat.
That's your IDE.

How are you deploying your web application to Tomcat?
Also, what Tomcat is it?  Is it embedded as part of Eclipse or standalone?



These are the important questions. You need to understand what a WAR is and how it is used.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using tomcat 8.5, I generated a project as follows:

WEB-INF / classes / WebCart / WebCartServlet.java

likewise I added the jsp and the web.xml

now I have a 404 error!
 
Tim Moores
Saloon Keeper
Posts: 5288
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

WEB-INF / classes / WebCart / WebCartServlet.java


Two problems:

1) The package name is "webcart", not "WebCart".

2) That's where WebCartServlet.class should be, not WebCartServlet.java.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ;

i have :

project -Web-INF/classes
               - webcart
                    - Cart.java
                    - WebCartServlet.java
          - Meta-INF
              - context.xml
         - WEB-INF
               - classes
                 -  webcart
                    - Cart.java
                    -WebCartServelet.java
              - panier.jsp
              - web.xml
         
 
Tim Moores
Saloon Keeper
Posts: 5288
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A source file does no good in WEB-INF/classes - that's were the class file needs to be.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:A source file does no good in WEB-INF/classes - that's were the class file needs to be.



I follow a certification EE java, but it is this exercise that is imposed.
It starts in this form previously written.
how can i edit my .class files instead of .java
 
Tim Moores
Saloon Keeper
Posts: 5288
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No editing - you compile the .java file which results in a .class file. The IDE does that for you, but it's possible it doesn't put the class files where they need to be. But after compilation they should be somewhere in the project folder, provided there were no errors.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:No editing - you compile the .java file which results in a .class file. The IDE does that for you, but it's possible it doesn't put the class files where they need to be. But after compilation they should be somewhere in the project folder, provided there were no errors.




I have no more error after compiling with Tomcat, I can not find the files.class!
Should you add a "target" directory for the tomcat?
to generate .class files in the "target" directory?
 
Tim Holloway
Saloon Keeper
Posts: 20510
115
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you must build a WAR and deploy the WAR to Tomcat.

You're trying to let your IDE (Eclipse) do all the thinking for you. If you understood how Java webapps and webapp servers work, you could make everything work without using Eclipse at all.

In fact, you have to do so in the Real World. No sane IT shop is going to run an IDE on a production server machine.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I installed my project in the webapps directory of tomcat,
I have trouble understanding between the compile command and the deployment in tomcat my directory is "/opt/apache-tomcat-8.5.34/webapps/fun/exo103/".
at the moment my servlet does not display a JSp page via the doGet method, but I have a 404 error!

how to differentiate the command >> javac myservlet
how to deploy in tomcat >> catalina
 
Tim Holloway
Saloon Keeper
Posts: 20510
115
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you don't install the "project" into Tomcat. As I said, Eclipse is not going to be around on a production Tomcat server. You only install the WAR into Tomcat. Tomcat doesn't care about and cannot use Eclipse projects. Or IntelliJ projects. Or Netbeans projects. et cetera.

The WAR can be in the form of a WAR file or an unzipped ("exploded") WAR. By default, Tomcat will take WAR files found in the Tomcat webapps directory and explode them into directories having the same base name as the WAR file's name. So mywebapp.war explodes to directory "mywebapp" and the webapp's URL context name would be "/mywebapp".

You cannot deploy WARs into sub-directories of the webapps directory. Only into the webapps directory itself. Tomcat would treat a file named TOMCAT_HOME/webapps/fun/exo103/myjsp.jsp as being deployed in the webapp whose context name was "fun" and the JSP would be accessible via the URL http://localhost:8080/fun/exo101/myjsp.jsp". It would not see that as a webapp named "exo101" - exo101 would simply be seen as a subdirectory of the "fun" webapp.
 
Philippe Ponceblanc
Ranch Hand
Posts: 200
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I left my first project here is the picture:



Here are my different code of the image:










now i would like to understand what url i have to put to make appear the page JSP == panier.jsp.

Then compremdre the mechanism of the javabean Cart.java and my servlet WebCartServlet.java.

The project is an e-commerce site with a basket to fill!
I do not ask that the have given me the site ready in hand, but only the filling of the basket, so that I assimilate this redundant structure!
 
Tim Holloway
Saloon Keeper
Posts: 20510
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ouch! My eyes! Screenshots are hard to read.

You cannot get panier.jsp using that directory layout. Nothing under the WEB-INF directory of a WAR can be accessed via a URL.

You have to move panier.jsp to the root of the WAR.

However, those screenshots don't tell us anything about the WAR, only about your IDE.

If you are using Maven to build a WAR, the place to put panier.jsp in the source project would be under its src/main/webapp directory. Maven will copy src/main/webapp's contents to the root of the WAR that it produces.
 
No holds barred. And no bars holed. Except this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!