• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Bert Bates-Struts Sample Appliation code

 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 -
<OPTION>pale

This will help you test your error message

ISSUE NO. 1-
The applicaition runs fine when you use the following URL

http://localhost:8080/strutsFirstApp/form.jsp

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

http://localhost:8080/strutsFirstApp/SelectBeer.do ( 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

ISSUE NO. 2 -

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

PLEASE HELP ME WITH THE ABOVE TWO ISSUES

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

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.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey some one please read the post

at least, Bert please read it
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

Thanks,

Bert
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Niranjan

Whe you invoke SelectBeer.do 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.
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 b_basham@yahoo.com

Cheers,
Bryan
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi bryan

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

Anyway, i sorted the problem myself.
Thanks.
 
I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic