This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

compilation error

 
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m a beginer of STRUTS n JSP..
here is my servlet code..which's not compiling..

package com.example.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Name extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
com.example.web.Work w = new com.example.web.Work();
w.setWork("Programmer!!");
request.setAttribute("Work",w);
RequestDispatcher vie = request.getRequestDispatcher("/name.jsp");
vie.forward(request,response);
}
}

ERROR :: cannot find class Work,,
its in d package "com.example.web.*"
and my servlet is also in the same package "com.example.web.*"
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to read about imports:

http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks james for consedring my error...

before posting i had use the statement
import com.example.web.*;

but still it was showing the same compilation error that" cannot find class Work "..
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you compiling this code? And what does your classpath look like?
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac -classpath ",;h:/tomcat/lib/servlet-api.jar" MyProjects/t/src/com/example/web/Name.java
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac -classpath ",;h.....

I think what is in bold above is your problem.
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh yeah...
during compiling my servlet..
it shows an error that "CANNOT FIND CLASS Work"
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you change the comma?
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes with dot..
like

javac -classpath ".;..." ...
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah you are in the wrong directory.Change to MyProjects/t/src and then run:

javac -classpath ".;h:/tomcat/lib/servlet-api.jar" com/example/web/Name.java

Also, make sure the following import is present in Name.java:
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still the same error!!

i think my "work.java" should not placed in the directory in which my servlet is placed...
what say about this??

servlet is in web directory... i think "work.java" should be in the model??
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey it was my mistake..
your last suggestion was right.. i was in the wrong directory...
thanks a lot man...
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you join me on facebook..
here is the link..

https://www.facebook.com/vamp.singhal
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic