Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Servlets and JSP

 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

Another newbie here, hope I am in the right place. I searched the forum some but can't find much about this book.

Has anyone read it? I just started with the first example and have a few questions.
 
arvind kushwaha
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go ahead with your question. Anyway you are welcome to this forum
 
Peeyush Bhadola
Greenhorn
Posts: 10
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am on chapter - 3 .. what's your doubt .. let's see if I can help.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You might be in the wrong place, but since you haven’t asked a question, I don’t know.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to know about the book? Or you have a query from the book?
 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sorry for the delay. I created the directories and compiled the servlet. First of all it doesn't show a button but an input box, which is not a problem, I just click inside the input box. Here's some more:

1. When I try http://localhost:8080/form.html it can't find it, but if I double click the file directly it loads it,

2. When I click 'enter' inside the input box the response url becomes

file:///C:/Users/Aydin/Desktop/Tomcat/apache-tomcat-6.0.35/webapps/Beer-v1/%E2%80%9DSelectBeer.do%E2%80%9D?%94color%94=%94amber%94

Let me know if I can provide more info

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to show us some code you are trying, without which it would be difficult to help you.
 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:You need to show us some code you are trying, without which it would be difficult to help you.


Ok,

First, I figured a few things. When I go to IE and enter http://localhost:8080/ I see Tomcat which tells me I have my server running, but then when I enter http://localhost:8080/Beer-v1/form.html but it gives me 404 error.

My $CATALINA_HOME is set to C:\Users\Aydin\Desktop\Tomcat\apache-tomcat-6.0.35\ and TOMCAT_HOME is set to the same path as well.

my form.html file is exactly the same as in the book, and it's simply a very basic html file.

Why can't Tomcat see my html file, any idea?

*************************************************************************************************************************
Edit -- Some updates
*************************************************************************************************************************

By looking at Tomcat's console I figured there was an error in web.xml which was simply using bad characters, if anyone cares I can explain further.

Now after I click "submit" I get this in the browser

http://localhost:8080/Beer-v1/%EF%BF%BDSelectBeer.do%EF%BF%BD?%EF%BF%BDcolor%EF%BF%BD=%EF%BF%BDamber%EF%BF%BD

and Tomcat says

type Status report

message /Beer-v1/%EF%BF%BDSelectBeer.do%EF%BF%BD

description The requested resource (/Beer-v1/%EF%BF%BDSelectBeer.do%EF%BF%BD) is not available.




 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

Apparently my question was too confusing. Let me ask a simpler one.

My example folder is located at
C:\Users\Aydin\Desktop\Tomcat\apache-tomcat-6.0.35\webapps\Beer-v1

my form.html is at C:\Users\Aydin\Desktop\Tomcat\apache-tomcat-6.0.35\webapps\Beer-v1\form.html

and my web.xml is in C:\Users\Aydin\Desktop\Tomcat\apache-tomcat-6.0.35\webapps\Beer-v1\WEB-INF
and here is web.xml itself

<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/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

</web-app>


is there anything wrong in the web.xml? Why can't Tomcat find my form.html
 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi,

Thanks, I will do that from now on.

a.a.

Bear Bibeault wrote:Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.



 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

By the way I resolved the problem. I was copy-and-pasting code from the book and the quotation marks were the wrong type which created all the problems. Once I fixed that problem code ran OK.

Thanks to anyone who got involved.

a.a.
 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I didn't think it was going to be easy. The second version is already giving me problems, but I am seeking a more general answer.
I am using the command line below to compile my BeerSelect.java file:

javac -classpath C:\Users\Aydin\Desktop\Tomcat\apache-tomcat-6.0.35\lib\servlet-api.jar;classes:. -d classes src\com\example\web\BeerSelect.java

In BeerSelect.java I have a

declaration but I get "package com.example.model does not exist" error. So my question are:
1. What exactly should my classpath be so that the compiler can find the com.example.model package?
2. Is the compiler using system environment or user environment when looking for classpath?

Thanks in advance
 
Antony Addy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again,

I hate to say that but I solved the problem myself again: instead of "classes:." it should have been "classes;." because in Windows the separator is a semicolon

If anyone needs further help I might be able to help now.

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for that, I just moved it to a correct forum. Glad that you solved the issue yourself. A positive from this is that you learnt something new
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic