HFSJ book: Cookie example chapter 6 plz Help :(

Hallo everyone, Right now I am doing the �simple custom cookie example� at Chapter 6 page 250 of the HFSJ book.

The example has 2 servlets: one to SET the cookie and the other one to GET the cookie.

1.In the XML do I need to include the 2 servlets? If yes, how can I include both of them in the servlet tag? And which one is gunna be in the servlet-mapping tag?

2.How is the form.html gunna look like?(the JSP page is exactly like the one in the book page 250) this is how it looks like right now **************************************** <html><body> <h1 align="center">Hello Test Cookie Page</h1> <form method="POST" action="checkcookie.do"> Enter your name<p>

1) The response to your first question is YES. Each time you want to use a servlet, you need to register the servlet in your DD. No exception to this rule so yes, you need to declar both servlets in the WEB-INF\web.xml of you app.

You do that just the way it was explained previously on the book. Your web.xml should be like this (assuming your classes are in the default package) :

2) Actually I do not see this JSP code in my own book! Anyway, the page should be like you wrote it, indeed.

You are submitting this form to the CookieTest Servlet, which sets the cookie, and redirects you to the cookieresult.jsp response page. The response page has a link that points to the second servlet (CheckCookie).

Hope this helps.

Regards, Leigh.

Leigh Parsons<br />SCJP 1.4, SCWCD (preparing)

Olivier Cleyman
Greenhorn

Joined: May 29, 2005
Posts: 14

posted May 30, 2005 05:24:00

0

Hi Moh,

I understand your concern now. The thing is you mixed two JSP.

In the book there is only one JSP d�tailed. The one that gives you the kink between de CookieTest Servlet and the CheckCookie Servlet. The Initial JSP containing the form is not in the book.

It should be like you or Leigh said.

If you do not want to write a JSP just change your doPost() method in the CookieTest Servlet into a doGet() method and acces the CookieTest directly with the url:

good luck... [ May 30, 2005: Message edited by: Olivier Cleyman ]

Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35

posted May 30, 2005 05:37:00

0

Guys it's still not working with me

this is the error i am getting, followed by my files ****************************************** HTTP Status 500 -

Calling new Kookie(....) will give you a 'NoClassDefFoundError'. (Unless of course you've declared your own Kookie class).

Change all Kookie references to Cookie, that should solve your problem.

Cheers,

Leigh.

Leigh Parsons
Greenhorn

Joined: May 30, 2005
Posts: 8

posted May 30, 2005 19:54:00

0

Hi Moh,

It's hard to tell what is causing your problem without seeing your code. Possibly the CookieTest class has been created in the wrong package (or you've put the class location in the DD <servlet-class> tag incorrectly).

Also check that your CookieTest.class file exists where it should.

If you email me all your files, I'll have a quick look and let you know what is stuffing up.

Use "leigh_c_parsons@hotmail.com", as I'm going on two weeks leave tomorrow :-)

Cheers,

Leigh.

H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34

posted May 30, 2005 21:13:00

0

I changed cookie to kookie bcoz it won't let me post anything in the forum if i use cookie.

Leigh Parsons
Greenhorn

Joined: May 30, 2005
Posts: 8

posted May 30, 2005 22:11:00

0

Hi again,

Sorry - my mistake.

I copied your code as you had it above, removed the "/servlet" portion from the defs in the <url-pattern> tags - ie. was: <url-pattern>/servlet/cookieTest.do</url-pattern> changed to: <url-pattern>/cookieTest.do</url-pattern>

and it works fine - give that a go.

Cheers,

Leigh.

Leigh Parsons
Greenhorn

Joined: May 30, 2005
Posts: 8

posted May 30, 2005 22:15:00

0

PS - Sorry - also change your links in the form and jsp to just reference the servlet. ie. change from: action="/servlet/cookieTest.do" to: action="cookieTest.do".

Hope this helps.

Leigh.

Jamed
Ranch Hand

Joined: Apr 17, 2005
Posts: 35

posted May 30, 2005 22:23:00

0

Thank you very much Leigh

You were right. The error was in Package declaration in my java classes. I didn't even put a package statment

thanks again Leigh for your help

HS,

Check all the things pointed out by Leigh. if it doesn't work let me know. and i'll try to help my email is mjamed2000@hotmail.com