aspose file tools*
The moose likes Servlets and the fly likes first servlet program from Headfirst book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "first servlet program from Headfirst book" Watch "first servlet program from Headfirst book" New topic
Author

first servlet program from Headfirst book

sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

My HTML file is as follows-


Below is DD .xml file -



Below is servlet code -



I have followed the same instructions as in the book.



On running the above command on the command prompt i successfully got the CoffeeSelect.class file. But if someone can verify the above command and also help me understand the following part of the above command "C:\Tomcat 5.25\common\lib\servlet-api.jar";classes;. if it is right!

My Development Environment-

For HTML file is E:\MyProjects\coffeeV1\web\form.html
For DD file is E:\MyProjects\coffeeV1\etc\web.xml
For servlet file is E:\MyProjects\coffeeV1\src\com\example\web\CoffeeSelect.java
For servlet .class file is E:\MyProjects\coffeeV1\classes\com\example\web\CoffeeSelect.class

My Deployment Environment-

For HTML file is C:\Tomcat 5.25\webapps\Coffee-v1\form.html
For DD file is C:\Tomcat 5.25\webapps\Coffee-v1\WEB-INF\web.xml
For servlet .class file is C:\Tomcat 5.25\webapps\Coffee-v1\WEB-INF\classes\com\example\web\CoffeeSelect.class


On running the following URL on the Google Chrome browser -
http://localhost:8080/Coffee-v1/form.html
the form gets displayed but when i click the Submit button
i get the following error-
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class com.example.web.CoffeeSelect
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:619)
root cause

java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class com.example.web.CoffeeSelect with modifiers ""
sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
java.lang.Class.newInstance0(Class.java:349)
java.lang.Class.newInstance(Class.java:308)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:619)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.

Apache Tomcat/5.5.25


And if i reload the page i get -

HTTP Status 404 - Servlet Ch3 Coffee is not available

type Status report

message Servlet Ch3 Coffee is not available

description The requested resource (Servlet Ch3 Coffee is not available) is not available.

Apache Tomcat/5.5.25


One more thing guys do i have to download the javax package? But i did not find such reference in the book. I also tried doing that but still i cannot get he above error out of my sight!

Hey friends and all you knowledgeable people kindly help me out with my first servlet program and help me out from getting discouraged and loose interest over this as i have been doing various modifications but none seems to work out. Help me guys!


Always believe in yourself
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Please someone reply ! Curiously, waiting for the help.
Antriksh jain
Greenhorn

Joined: Feb 22, 2013
Posts: 2
sarvesh dikonda wrote:Please someone reply ! Curiously, waiting for the help.


Have you tried cleaning your Tomcat server? :

1 clicking on the Tomcat server at the server window.
1. Clean Tomcat work directory.
2. Clean Tomcat.
3. Clean project.
4. Refresh project.
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 108

java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class com.example.web.CoffeeSelect with modifiers ""

your class is defined with a default access modifier.
class CoffeeSelect extends HttpServlet

Try changing it to public.


Thanks,
Tushar (SCJP 1.5)
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Superb guys! I am happy! Thank you both T Mishra and Antriksh jain for your precious suggestions. Now i can move ahead happily! This is why i love this forum so much. Keep up the the good work guys! God bless!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: first servlet program from Headfirst book