aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Cannot get Servlets Demystified  Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Cannot get Servlets Demystified  Problem" Watch "Cannot get Servlets Demystified  Problem" New topic
Author

Cannot get Servlets Demystified Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

head first servlets


pg-31

followed upto steps 4
cannot get the step 5

F:\SCWCD>cd project1

F:\SCWCD\Project1>javac -classpath F:\SCWCD\Apache Software Foundation\Tomcat 7.
0\lib\servlet-api.jar classes src/Ch1Servlet.java
javac: invalid flag: Foundation\Tomcat
Usage: javac <options> <source files>
use -help for a list of possible options


help


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
mohitkumar gupta wrote:
head first servlets


pg-31

followed upto steps 4
cannot get the step 5

F:\SCWCD>cd project1

F:\SCWCD\Project1>javac -classpath F:\SCWCD\Apache Software Foundation\Tomcat 7.
0\lib\servlet-api.jar classes src/Ch1Servlet.java
javac: invalid flag: Foundation\Tomcat
Usage: javac <options> <source files>
use -help for a list of possible options


help



Howdy !

1) If some file path contains space character, you should enclose that path in single quotes or double quotes, i.e. try this command:



2) Not sure what the word classes means in your command. If this is a part of path, then command line should look like:



Let me know if this helped.

Best regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634


now i am getting the followin error

F:\SCWCD\Project1>javac -classpath "F:\SCWCD\Apache Software Foundation\Tomcat 7
.0\lib\servlet-api.jar" classes src/Ch1Servlet.java
error: Class names, 'classes', are only accepted if annotation processing is exp
licitly requested
1 error
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
mohitkumar gupta wrote:
now i am getting the followin error

F:\SCWCD\Project1>javac -classpath "F:\SCWCD\Apache Software Foundation\Tomcat 7
.0\lib\servlet-api.jar" classes src/Ch1Servlet.java
error: Class names, 'classes', are only accepted if annotation processing is exp
licitly requested
1 error


Howdy !

Did you read my note 2) ?

The classes word in your command is invalid. I don't have a book so can not tell what it should be:

a) either part of classpath, then it must be added to jar file, separated by semicolon:



b) either part of path with Java source code file, then it should be added to second part:



c) one possible way - classes may define destination folder, then it must be prepended with -d key:



P.S. I'm kind of surprised since this is basic syntax tested heavily on SCJP exam, and SCJP is prerequisite for SCWCD

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

I got confused


anyways thanks for help
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
mohitkumar gupta wrote:I got confused


anyways thanks for help


Ok... I managed to get access to that page on google books web site.

Please read my point c) from second reply. You missed -d option for java compiler.



After you run the command, you should get Ch1Servlet.class inside Project1/classes folder.



[Thumbnail for syntax.gif]

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

have Apache Tomcat/7.0.4
i started the service by clicking start service icon in the taskbar
Getting the following,when i typed
http://localhost:8080/ch1/Serv1
in the browser

i


HTTP Status 404 - /ch1/Serv1

type Status report

message /ch1/Serv1

description The requested resource (/ch1/Serv1) is not available.

the code in web.xml is


F:\SCWCD\Apache Software Foundation\Tomcat 7.0\webapps\ch1\WEB-INF-It contains the web.xml file
F:\SCWCD\Apache Software Foundation\Tomcat 7.0\webapps\ch1\WEB-INF\classes-It contains the Ch1Servlet.class
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

hey Mikalai Zaikin ,i have resolved the earlier problem but now,when i type the localhost:8080/ch1/Serv1

i don't get any output

the details are in the previous thread


please help
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
mohitkumar gupta wrote:hey Mikalai Zaikin ,i have resolved the earlier problem but now,when i type the localhost:8080/ch1/Serv1

i don't get any output

the details are in the previous thread


please help


Hello,

The problem you have means that Tomcat 7.0 can not "see" the servlet you're invoking (HTTP code 404). The servlet probably was not properly deployed into container. You can look at Tomcat's log files to learn more.

The HF S&JSP book was published about 2004, that time the latest servlet specification was 2.4 (now - 3.0), and the book used Tomcat 5.0 servlet container for it's examples. If you're preparing to SCWCD 5.0 you should know which versions of specifications it covers and which servlet container is a reference implementation for that specification. While Tomcat 7.0 must support Servlet 2.4, I advise you to use Tomcat 5.0 - as the book authors used it for examples.

Best regards,
MZ
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Hello,

The problem you have means that Tomcat 7.0 can not "see" the servlet you're invoking (HTTP code 404). The servlet probably was not properly deployed into container. You can look at Tomcat's log files to learn more.

The HF S&JSP book was published about 2004, that time the latest servlet specification was 2.4 (now - 3.0), and the book used Tomcat 5.0 servlet container for it's examples. If you're preparing to SCWCD 5.0 you should know which versions of specifications it covers and which servlet container is a reference implementation for that specification. While Tomcat 7.0 must support Servlet 2.4, I advise you to use Tomcat 5.0 - as the book authors used it for examples.

Best regards,
MZ


i have installed tomcat version 5.5
i am using jdk 1.6 version
path-
C:\Program Files\Java\jdk1.6.0_23\bin

still i am getting the same error

-------
HTTP Status 404 -

type Status report

message

description The requested resource () is not available.

Apache Tomcat/5.5.31

------


i have made the ch1 folder as follows:
E:\SCWCD\Apache Software Foundation\Tomcat 5.5\webapps\ch1\WEB-INF\classes
WEB-INF contains web.xml and classes folder
while classes contains Ch1Servlet.class

is some evironment variable need to be set for tomcat
?
i just choose the jdk installation directory while installing tomcat

i put the
http://localhost:8080/jsp-examples/in the browser
and got
----------------------


HTTP Status 404 - /jsp-examples/

type Status report

message /jsp-examples/

description The requested resource (/jsp-examples/) is not available.

Apache Tomcat/5.5.31


----------------------------
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
Hello,

Status code HTTP 404 means resource not found, 2 reasons:
1) typo in URL
2) resource was not deployed

You might open admin console (or whatever it called for Tomcat) or log files and verify if "jsp-examples" web-application was deployed.

Also, refer Tomcat 5.5 documentation on how to deploy resources.

If you want servlet container to show anything on URL which ends with "/", you should provide either URL pattern for default resource, or welcome file in web.xml, like:



As an option, you can try to download Netbeans 6.9 - it already bundled with GlassFish 3, and you can run servlets and JSP by right click on the file.

Best regards,
MZ
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

THe web.xml contains:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”"
version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>


i am not able to get what is the error in the web.xml file

The error page in browser shows:

HTTP Status 404 -

type Status report

message

description The requested resource () is not available.

Apache Tomcat/5.5.31


the following was found in the log file:

---------------------------------------------------------------

Dec 14, 2010 2:21:27 AM org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/ch1/WEB-INF/web.xml
java.io.UnsupportedEncodingException: ISO-8851-1
at sun.nio.cs.StreamDecoder.forInputStreamReader(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.createReader(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.setEncoding(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanXMLDeclOrTextDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XMLDeclDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(ContextConfig.java:348)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1053)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4184)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:980)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:943)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1203)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Dec 14, 2010 2:21:27 AM org.apache.catalina.startup.ContextConfig start
SEVERE: Marking this application unavailable due to previous error(s)
Dec 14, 2010 2:21:27 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Dec 14, 2010 2:21:27 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/ch1] startup failed due to previous errors
Dec 14, 2010 2:21:27 AM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Dec 14, 2010 2:21:27 AM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Dec 14, 2010 2:21:27 AM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
Dec 14, 2010 2:21:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 774 ms

---------------------------------------------------------------------------------------

if i change the ISO-8851-1 to ISO-8859-1in web.xml ,i get the following outtput in the browser


html> <body><h1 align=center>HFs Chapter1 Servlet</h1><br>Tue Dec 14 02:24:20 IST 2010</body></html>


Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
1) Regarding encoding in web.xml, please refer this thread :


There is a type mistake in the book. Valid ISO encoding version is "ISO-8859-1".


2) Regarding the output with embedded HTML tags, I believe this happens because opening <html> tag does not have the '<' bracket. Please, check the source code of servlet and add < before html>

Good luck,
MZ
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3233
    
    7
Also, please check the HF S and JSP errata page :

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

thanks Mikalai Zaikin
you were a great help to me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot get Servlets Demystified Problem