File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Bert Bates-Struts Sample Appliation code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Bert Bates-Struts Sample Appliation code" Watch "Bert Bates-Struts Sample Appliation code" New topic

Bert Bates-Struts Sample Appliation code

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Hi Bert,

The Struts part in the final chapter of the book has been really covered well.
I tried running the code given. Everything works fine.
But the beer app in the sarting chapter ( i guess chapter 3 ) uses form.html as a page where user selects the beer
The app in the final chapter tells us to use form.jsp. A JSP should be used because -

"We need to pop error message ( in case the user selects a invalid beer ). Such a error message can be popped only on JSP"

The point that i wanted to bring to your attention is -

The code for form.jsp is not at all given in the book. It gave me a lot of pain in the a**, to figure out how to code the JSP
I referred Struts - Complete Reference by Schieldt. But i do agree the pain was all the worth.
FYI, all ranchers add this code to the form.html file of chapter 3, and rename the file as form.jsp.

<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %> < add this at the top )
<html:errors/> ( i added this just after the <BODY> tag of the file, but i guess it can be added anywhere in the file)

note - if anyone wants explanantion for the above struts tag, i will give it.

Also add this to the drop - down box's code -

This will help you test your error message

The applicaition runs fine when you use the following URL


But gives a NullPointerException ( in the borwser window ) if you use the following URL

http://localhost:8080/strutsFirstApp/ ( after seeing the stack trace i guess one should add the <controller> tag to
the struts-config.xml )
I should not get any NullPointerException as we have coded the web.xml to handle all the .do URLs.s


When i start the server i get a exception trace, prominent messages of which are -

"element type message resources must be declared "

" the content of element type "struts-config" must match "(data sources?, form beans ?, global forwards ?, action-mappings ?)"

I have typed in the xml file as it is give in the book


HANG ON - By the time i posted this on the ranch, i solved the issue 2. The solution is here for your reference -

Solution to Issue No 2 - I was using this in struts-config.xml -

<!DOCTYPE struts-cofig PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"

If you see properly i missed a 'n' on the first line I corrected this but it didnt solve the problem. Did some googling and found that
xml file is improper as per the stuts DTD. I am using a struts 1.2 so the second line should have a 1.2 instead of 1.0
This solves the problems in ISSUE 2 and we dont see any server spit out when we start the server.

Bert Please inlcude some directions in the book that take care of the version mismatch problem as above.Its difficult for begineers to
figure out the bug, but i do agrree that the pain that i took to solve the issue was all worth.

I have uploaded the entire code on [ link here ]. You can download it and save your preicious time

Still Issue 1 needs to be sorted
Please Help

Thanks in advance.

SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
hey some one please read the post

at least, Bert please read it
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Hi Niranjan,

I'm stuck in a foreign land for the next few days and I can surf the internet and receive emails, but I can't send any

When I get back I will ask Bryan Basham to take a look at this - he's the real struts expert!



Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
Hi Niranjan

Whe you invoke the controller is invoked. Then it will create the specified ActionForm anew (because it is configured to have request scope), attempt to populate it from the request and then run the validate() method.

The color variable is not initialised, so will be null, and validate goes on to use it to do an indexOf method call, which will give a NullPointer exception.

I'm guessing that's your error, but I've not deployed the code nor seen your stack trace. When you invoke it via form.jsp, I'm betting you have some fields that set a color request parameter, which will populate the ActionForm at the previous step.
Bryan Basham
Ranch Hand

Joined: Apr 30, 2001
Posts: 199
Hello Niranjan,

I was not able to follow your link (it didn't show up in my browser) so I am not able to try your code out. Also, you could include the actual stack trace and that might give us another clue.

Alternatively, you can download the source code from Kathy and Bert's website:
Head First Servlets and JSPs and compare it with your own code.

I don't check JavaRanch very often, so feel free to email me directly at

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
Hi bryan

I have included the server stack messages in my post.
Please see it carefully.

Anyway, i sorted the problem myself.
I agree. Here's the link:
subject: Bert Bates-Struts Sample Appliation code
jQuery in Action, 3rd edition