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

head first, very basic servlet

deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
I am trying to do chapter 3 in HFSJ, its been 14 hours of continuous perspiration and I am not been able to run a single servlet on my computer of my own

error: HTTP Status 404 - /Beer-v1/SelectBeer.do

my web.xml looks like this :





my html files looks like this:



all the directory structure is as per the book, and checked atleast a thousand times. I put BeerSelect.class file in D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1\WEB-INF\classes\com\example\web\



catalina log files show :

INFO: Deploying web application directory D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\ch1
May 5, 2013 3:26:52 AM org.apache.catalina.startup.ContextConfig parseWebXml
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(StreamDecoder.java:52)
at java.io.InputStreamReader.<init>(InputStreamReader.java:83)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.createReader(XMLEntityScanner.java:1901)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.setEncoding(XMLEntityScanner.java:445)



but my web.xml encoding is ISO-8859-1 as i posted earlier, seems like tomcat is using another web.xml << this is only my thought, dont know if its true. Any help is appreciated.
thank you
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Are you sure the web.xml that is located at D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\ch1 has 8859 and not 8851 encoding?


~ Mansukh
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
the web.xml that is located at D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\ch1 had encoding 8851 and I was not able to run that servlet also, but I left it, I tried after changing the port to 8859 also but that didnt help, next i removed ch1 directory from webapps, thats also not working
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

8859 is not a port. Do you understand what character encoding is?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Your error surely points to the xml in the above ch1 directory. Can you show me that web.xml which is in the /ch1/WEB-INF directory?
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Bear Bibeault wrote:8859 is not a port. Do you understand what character encoding is?


thank you so much for the reply,

by saying the encoding is 8859, I meant the encoding is ISO-8859-1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

So why did you change the port?

Verify that your files use the correct encoding.
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:Your error surely points to the xml in the above ch1 directory. Can you show me that web.xml which is in the /ch1/WEB-INF directory?


though I removed ch1 directory now, this has nothing to do with my current project, that is Beer-v1.

but for the info, it was like this :


Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I can clearly see that it has 8851 encoding. Can you change it to 8859 and check again please?
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Bear Bibeault wrote:So why did you change the port?

Verify that your files use the correct encoding.


I cant understand, why you are saying that I changed the port, I never said that I changed the port. Yes copied the web-app tag and its attribute-value from pre installed projects in tomcat, and hence the encoding can't be wrong.
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:I can clearly see that it has 8851 encoding. Can you change it to 8859 and check again please?


yes mansukh, I already tried that .. Hey I think there is some misunderstanding, this is not the web.xml I am talking about, the problem is, tomcat is not able to see web.xml in

D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1\WEB-INF\web.xml
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

So now what is the error / exception that you are seeing when trying to start tomcat? Please share that.
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
My current web.xml is like that

deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:So now what is the error / exception that you are seeing when trying to start tomcat? Please share that.


I am not getting any error when I am starting tomcat. I can access the form.html that I have stored in

D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1\form.html

the HTML looks like this :

deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
the problem is as soon as Press submit, it says


HTTP Status 404 - /Beer-v1/SelectBeer.do

type Status report

message /Beer-v1/SelectBeer.do

description The requested resource is not available.

Apache Tomcat/7.0.39
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
while starting tomcat I am getting this output :

java.lang.UnsatisfiedLinkError: D:\software\eclipse-jee-indigo-SR1-win32\apache-
tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\bin\tcnative-1.dll: Can't load AM
D 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at org.apache.tomcat.jni.Library.<init>(Library.java:42)
at org.apache.tomcat.jni.Library.initialize(Library.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListen
er.java:180)
at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifec
ycleListener.java:85)
at org.apache.catalina.connector.Connector.setProtocol(Connector.java:59
5)
at org.apache.catalina.connector.Connector.<init>(Connector.java:69)
at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreate
Rule.java:62)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1
276)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startEle
ment(AbstractSAXParser.java:501)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.
emptyElement(AbstractXMLDocumentParser.java:179)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanStartElement(XMLDocumentFragmentScannerImpl.java:1337)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2740)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
MLDocumentScannerImpl.java:645)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.
java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Ab
stractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
at org.apache.catalina.startup.Catalina.load(Catalina.java:610)
at org.apache.catalina.startup.Catalina.load(Catalina.java:658)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
May 5, 2013 10:41:47 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performanc
e in production environments was not found on the java.library.path: C:\Program
Files (x86)\Java\jdk1.6.0\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\W
indows;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files (x86)\J
ava\jdk1.6.0;C:\Program Files (x86)\Windows Live\Shared;;C:\Program Files\WIDCOM
M\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Us
ers\varun\AppData\Local\Android\android-sdk\tools;C:\Users\varun\AppData\Local\A
ndroid\android-sdk\platform-tools;C:\Program Files (x86)\MySQL\MySQL Server 5.0\
bin;C:\Program Files (x86)\Java\jdk1.6.0\bin;C:\Users\varun\AppData\Local\Androi
d\android-sdk\tools;C:\Users\varun\AppData\Local\Android\android-sdk\platform-to
ols;
May 5, 2013 10:41:48 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
May 5, 2013 10:41:48 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 5, 2013 10:41:48 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 763 ms
May 5, 2013 10:41:48 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 5, 2013 10:41:48 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.39
May 5, 2013 10:41:48 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory D:\software\eclipse-jee-indigo-SR1-win
32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1
May 5, 2013 10:41:48 AM org.apache.catalina.startup.HostConfig deployDirectory
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I should have caught this earlier when I saw D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1\WEB-INF\classes\com\example\web\
. Anyways, do you understand the problem now? Do you know why are you seeing :

java.lang.UnsatisfiedLinkError: D:\software\eclipse-jee-indigo-SR1-win32\apache-
tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\bin\tcnative-1.dll: Can't load AM
D 64-bit .dll on a IA 32-bit platform


It is because you are trying to run tomcat 64 bit container inside eclipse 32 bit environment. These need to be of same architecture. Following?
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:I should have caught this earlier when I saw D:\software\eclipse-jee-indigo-SR1-win32\apache-tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\webapps\Beer-v1\WEB-INF\classes\com\example\web\
. Anyways, do you understand the problem now? Do you know why are you seeing :

java.lang.UnsatisfiedLinkError: D:\software\eclipse-jee-indigo-SR1-win32\apache-
tomcat-7.0.39-windows-x64\apache-tomcat-7.0.39\bin\tcnative-1.dll: Can't load AM
D 64-bit .dll on a IA 32-bit platform


It is because you are trying to run tomcat 64 bit container inside eclipse 32 bit environment. These need to be of same architecture. Following?


Yes thank you mansukh.

In this case what should I do? should I reinstall my jdk for 64 bit of there is some tweak to get pass through it ?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Better replace tomcat 64 bit with tomcat 32 bit than interfering with java installation. It comes as zip. Just extract it in a folder, copy your web project there and try again.
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
I downloaded 32 bit version of tomacat and copied all my project files in webapp folder of this tomcat, next i changed the CATALINA_HOME to point to the location of this new tomcat. Still I am getting the same error, I checked catalina log and it says :


May 5, 2013 11:50:21 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:179)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:338)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:416)
May 5, 2013 11:50:24 AM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.6.
May 5, 2013 11:50:24 AM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
May 5, 2013 11:50:26 AM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized with version OpenSSL 1.0.1d 5 Feb 2013
May 5, 2013 11:50:26 AM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 5, 2013 11:50:26 AM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
May 5, 2013 11:50:26 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1871 ms
May 5, 2013 11:50:26 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 5, 2013 11:50:26 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.37
May 5, 2013 11:50:26 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory Beer-v1
May 5, 2013 11:50:26 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
May 5, 2013 11:50:26 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
May 5, 2013 11:50:27 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
May 5, 2013 11:50:27 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
May 5, 2013 11:50:27 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
May 5, 2013 11:50:27 AM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 5, 2013 11:50:27 AM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
May 5, 2013 11:50:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1090 ms
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Are you seeing this when you start the server or when you stop it?
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:Are you seeing this when you start the server or when you stop it?


when stopping the server, thanks to you, Its starting just fine. But the problem still persist.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Are there any errors in start up logs? Also, try going to http://localhost:8080. You should see the tomcat admin console if tomcat is correctly installed.
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
Mansukhdeep Thind wrote:Are there any errors in start up logs? Also, try going to http://localhost:8080. You should see the tomcat admin console if tomcat is correctly installed.


server is starting up just fine:

catalina_log:

May 5, 2013 12:53:28 PM org.apache.coyote.http11.Http11AprProtocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
May 5, 2013 12:53:28 PM org.apache.coyote.ajp.AjpAprProtocol pause
INFO: Pausing Coyote AJP/1.3 on ajp-8009
May 5, 2013 12:53:29 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
May 5, 2013 12:53:30 PM org.apache.coyote.http11.Http11AprProtocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
May 5, 2013 12:53:30 PM org.apache.coyote.ajp.AjpAprProtocol destroy
INFO: Stopping Coyote AJP/1.3 on ajp-8009
May 5, 2013 12:53:32 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27 using APR version 1.4.6.
May 5, 2013 12:53:32 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
May 5, 2013 12:53:33 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized with version OpenSSL 1.0.1d 5 Feb 2013
May 5, 2013 12:53:33 PM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 5, 2013 12:53:33 PM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
May 5, 2013 12:53:33 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2042 ms
May 5, 2013 12:53:33 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 5, 2013 12:53:33 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.37
May 5, 2013 12:53:33 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory Beer-v1
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ch1
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
May 5, 2013 12:53:34 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
May 5, 2013 12:53:34 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 5, 2013 12:53:34 PM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
May 5, 2013 12:53:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1033 ms


Recompiled my java files again and replaced .class file but still no luck.

Checked localhost:8080, its running fine, and showing the preconfigured page of tomcat.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

What address are you entering in the browser address bar?
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
ARGHHHH!!! got it finally. HUH got it finally. In the action attribute in my HTML file I put SelectBeer.do with capital S, but my web.xml file was expecting something like selectBeer.do with small s. Changed my Web.xml to :



I dont know how to thank mansukhdeep, who was with me all the time without losing patience.
I feel embarrased that I was stuck at this silly mistake since 18 hours.

thank you so much for you support
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

You are always welcome. We all make mistakes. The idea is to learn from them and not repeat them.

Deepak wrote: who was with me all the time without losing patience.


No, I am not a patient person. There are a lot of people better than me, much better. I just try and learn from them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: head first, very basic servlet