This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in the source file

 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried a servlet program where i placed the .java file in bin and in the source. I tried compiling both. It shows error in import javax.servlet, http methods. What is the reason for these errors?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do the errors say? What do you mean by this:

where i placed the .java file in bin



 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by "bin", but it doesn't sound like the right place for source files. How are you adding the jar file that contains the javax.servlet and javax.servlet.http packages to the classpath?
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to create class file first in src inside webapps/.../src/Helloworld.java and then tried keeping the source file inside bin I also tried keeping the source file inside d: setting home,path and class path. Please let me know the correct procedure.
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which package should i add i mean which jar file should i add other than servlet-api.jar and where should i add it?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter where the source files are, but whatever "bin" is (I can't tell from your post), it sounds like a place for binaries, not source code.

For compiling servlets you don't need anything else but servlet-api.jar in the classpath. You can achieve that by compiling somewhat like this:

javac -cp "c:\this\is\the\path\to\servlet-api.jar" MyServlet.java

This assumes that the .java file is in the current directory, and that there are no complications arising from packages. If there are, then this may help: http://download.oracle.com/javase/tutorial/java/package/managingfiles.html
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
Thanks for your effort. I just found out the silly mistake which i did with setting home and classpath. Its working fine now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic