Go To Homepage



Book Details
Beginning JSP™, JSF™ and Tomcat™ Web Development: From Novice to Professional book cover
  • By Giulio Zambon Michael Sekler
  • ISBN13: 978-1-59059-904-4
  • ISBN10: 1-59059-904-7
  • 448 pp.
  • Published Nov 2007
  • Print Book Price: $39.99
  • eBook Price: $27.99



Errata Submission

If you think that you've found an error in Beginning JSP™, JSF™ and Tomcat™ Web Development: From Novice to Professional, please let us know about it. You will find any confirmed erratum below, so you can check if your concern has already been addressed.

Submit Errata
Beginning JSP™, JSF™ and Tomcat™ Web Development: From Novice to Professional (978-1-59059-904-4)

Errata

Issue Author's Response
I run ebookshop project of chapter 1 and it doesn't work. I get the homepage (figure 1-8 ) but when I click «Add to Cart», I have the following error:
exception

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:443)
java.lang.Integer.parseInt(Integer.java:514)
ebookshop.ShoppingServlet.getBook(ShoppingServlet.java:101)
ebookshop.ShoppingServlet.doPost(ShoppingServlet.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I run Tomcat6 on SUSE 11.2 and I downloaded all sources and compiled files from apress.
Thanks
The README.TXT, concerning ebookshop, says: "To test it, copy the whole folder to webapps and type in the browser: http://localhost:8080/ebookshop

I have just done it and it works as described in the book. But I have a couple of comments I would like to make:

1. The trace you included in your question shows that the exception occurred because the code attempted to execute java.lang.Integer.parseInt with a non-numeric string as argument. Now, parseInt only appears once in the source file ShoppingServlet.java as downloadable from Apress, in line 94, not 101 as shown in your trace.

2. The trace also shows that the exception originated from line 60 of ShoppingServlet.java, within the method doPost. In the code downloadable from Apress, getBook is invoked in like 61 of doPost, not in line 61.

The only conclusion I can draw is that you have modified the original code. You said you compiled the downloaded files. But the download package from Apress also includes the compiled class files. I recommend that, first of all, you try the package as it is.

I am happy for you to play with the programs. It's the best way to learn, but I suggest that you make a small change at the time and verify that everything still work after every individual update.
Regarding the following problem:
"...I can't compile the ShoppingServlet java class in Chapter 1, page 22. The compile_it bat routine cannot find javax.servlet..."
I spent a few hours the compile correctly. javax.servlet is a librairy of TOmcat and not of JDK.
We have to include Tomcat library' path in compilation.
I modified the compile_it.bat like this and it worked:
set tomcat_lib="C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"
javac -verbose -deprecation -Xlint:unchecked -classpath %tomcat_lib%;classes src\%fil%.java
You are right. Thanks for this comment. compile_it.bat must have worked for us because we had a duplicated library, although it is impossible to confirm it at this stage. Our apologies. Obviously, you can also write javac -verbose -deprecation -Xlint:unchecked -classpath "C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar";classes src\%fil%.java without setting tomcat_lib. Note that it would be useless to add the servlet-api.jar to CLASSPATH, because the content of javac option replaces the content of the environment variable.
Chapter 01, Page 10. The last paragraph says: "Figure 1-8 shows the Ebookshop's home page, which you see when you type http://localhost:8080/ebookshop in your browser's address field." But, of course, this isn't so, since we have not installed the ebookshop. I've done everything in App 1 and followed everything so far, so I tried copying the Chapter 1 ebookshop folder into the Tomcat document root, but then I just got errors. I also tried using the compile_it batch file, but could only compile Books.java. The ShoppingServlet would not compile. Both classes are in the WEB-INF\classes\ebookshop folder, though, so I don't know what's wrong. Perhaps, for the sake of clarity, we should have said to install the ebookshop application before trying to execute it, but I confess that it didn't pass thorugh our mind! Sorry about that.

I just copied the folder ebookshop to the webapps folder and
http://localhost:8080/ebookshop
worked without any problem. If with "Tomcat document root" you mean the webapps folder, I don't see what could have gone wrong. Unfortunately, unless you specify in more detail what errors you are getting, it is impossible to diagnose the problem.

The ShoppingServlet will not compile unless the compiler is told where to look for the javax.servlet library. The library is in the file servlet-api.jar contained in the folder
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\

Edit compile_it.bat and attach
;..\..\..\lib\servlet-api.jar
to
-classpath classes
so that it becomes
-classpath classes;..\..\..\lib\servlet-api.jar

That said, Book.class and ShoppingServlet.class are already present in the folder
... webapps\ebookshop\WEB-INF\classes\ebookshop\
Therefore, you don't need to recompile them.
In the Appendix A - I am setting up a new XP Pro with the required applications and libraries to get all examples working.

However, up to the stage of XPath - everything runs fine. But then after copying the 4 libraries from the XPath instructions, loading http://localhost:8080/ simply stalled and refused to display the page. Have you any idea what might be causing this issue?
Are you starting from a clean installation? The only possible cause I can come up with is that there are some conflicts between the libraries in the Tomcat lib folder
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
and other libraries in the WEB-INF\lib folder of your application.

Otherwise, I don't see how Tomcat could get stuck by adding some jars to its lib folder. Those jars are not used unless you use XPath...

To be on the safe side, I just reinstalled the latest version of xalan (2.7.1) and it worked fine with JDK 6u14 and Tomcat 6.0.18. I didn't bother to download libraries from the xerces-j directory as suggested in point 5 of page 262.

In fact, the differences between the current packages and those most recent when the book was written (JDK 6u1, Tomcat 6.0.13, and xalan 2.7.0) are minimal.

I can only recommend that you make a clean installation from scratch with the latest packages. :-(

And don't forget to perform the tests as you go...

Ciao, Giulio.
On page 52, listing 2-8 shows a document named "weekday.jsp". In the second paragraph under it, the URL string being suggested is

http://localhost/:8080/tags/weekdays.jsp?d=2007-12-25

Do you see how you have suddenly pluralized weekday.jsp and changed it to weekdays.jsp?

Thanks

Bob Cochran
You are right. Thanks for pointing it out. The URL should have been

http://localhost/:8080/tags/weekday.jsp?d=2007-12-25

Well spotted!

Ciao, Giulio.
Hi, this is in reference to Chapter 2, pages 48-55, which discuss JSP's Tag Extension Mechanism. The steps described for building both bodyless and bodied custom actions do not sufficiently describe how exactly to pass parameters to the tag handlers. For example, listing 2-11 has this line of code:

weekday ${param.d}: <wow:weekday date="${param.d}"/><br>

But there is no discussion of how to pass the parameter itself to the tag handler. I admit that on page 52 you state:

"If you type http://localhost:8080/tags/weekdays.jsp?d-2007-12-25 in the browser...", but there is no other significant discussion at this point for how to pass parameters. You might want to show how to do this. I'm guessing it needs to be done in the web.xml file since experimenting with the tag library descriptor file wow.tld shows I can't pass a parameter value in that. Many readers like me tend to use IDEs such as Eclipse or Netbeans. I myself use Rational Application Developer which means I'm using their bundled versions of the WebSphere Application Server. And it is not always obvious how to pass parameters within an IDE. Thanks, Bob Cochran
Hi Bob,

Thanks for your question.

I am not sure I understand what the issue is. I think you are confusing parameters passed to the JSP page and custom action pattributes passed to the tag handler when you execute the action. Perhaps this is due to the fact that in the example I wrote a page parameter directly in the custom action.

The bodyless action "weekday" described in the previous section shows how to define an action attribute in the the TLD by means of the <attribute> tag.

When I developed WeekdayBodyTag, I removed the "date" attribute that was present in WeekdayTag because I wanted to pass the date to the action by writing it in its action body.

Nothing would prevent you from keeping the attribute in the bodied action.

I hope this help. If not, please restate the problem in more detail, so that I can help you further.

Ciao, Giulio.
This is probably a simple one: I can't compile the ShoppingServlet java class in Chapter 1, page 22. The compile_it bat routine cannot find javax.servlet. I've downloaded the latest JDK 1.6, update 13. With that installation, there was no separate JRE directory (although, an older one does exist for 1.6, but update 7). I could download JEE 5 directly, but I'm not sure if I need to add anything to the PATH variable, etc. Have you added "C:\Program Files\Java\jdk1.6.0_13\bin" to the Path system variable?

Every time I install JDK/JRE and Tomcat on a new PC, I religiously follow the instructions contained in the book, to be sure that they still result in a successful installation of the environment.

I had been running Tomcat 6.0.18 with JDK 6u10 without any problem. I just intalled JDK 6u14 and saw no difference.

In any case, I was surprised to hear that your JDK 6u13 didn't include a JRE directory. I checked JDK 6u10 and 6u14 and (to my relief :-) they both have it.

Ciao, Giulio.
I have experienced a problem with IE handling the Javascript statement

ddObj.appendChild(new Option(currentDays));

This Chapter 3, pages 106-107. I found that Firefox correctly handles this code but that IE was incorrectly showing a blank entry. However, when the date was copied (1 -> 2) it correctly displayed in 2 if date 2 was uncorrupted.

In order to address this I have replaced this line with the following, which seems to work in both IE and Firefox.

var o = new Option();
o.value = currentDays;
o.innerHTML = currentDays;
ddObj.appendChild( o );

I am a novice at this so there may be a better way but I thought I'd flag it up.
Thanks for your comment.

I haven't been able to reproduce the problem. The original code works perfectly well with my IE. Perhaps we are using different versions of the browser. Mine is version 7.0.6001.18000.

I don't see why setting up the option in a variable should make a difference.

Perhaps the following will also work for you:
var o = new Option(currentDays);
ddObj.appendChild( o );

In any case, this might help other readers who have encountered the same problem. Thanks again, Giulio.
I just discovered a typo in the third-last bulleted point of page 358.

It should read: SELECT COUNT(*) FROM [...], without any space after the token COUNT.

Sorry about that, Giulio.
I forgot to say that with the space you get a syntax error.

Ciao, Giulio.
I've read the book, It's wonderful book but the example "eshop" not running.

I've follow "Appendix A: Installing Anything" to installed

- JDK 6 Update 1
- Apache Tomcat 6.0.13
- MySQL 5.0.41 Win32
- MySQL Connector-java-5.0.6
- MySQL GUI tools 5.0 r13 win32
- Win XP Pro SP3

and then, I copy the eshop folder from chapter 2 folder (sourcecode downloaded) to \..\webapps\eshop\ of Apache Tomcat server. But nothign display in browser (except some HTML element). No catagories, carts, listing, e.t.c...

Can you guide me to set it up ?
Pls send me a email to thonvyvn@yahoo.com if you can.
Thanks a lot.

Viet, Bui Quoc
Before you can use the application, you have to create the database with the categories and the books. I believe that you haven't done so. That's paerhaps why you only see the HTML.

I suspect that you have installed the packages but without executing the tests described in Appendix A. Unfortunately, the test on page 258, immediately below Figure A-5, tells you precisely what you need to do to create the database.

To be sure that you have copied the application correctly, you might like to take the file eshop.war from the folder _AppendixG of the software package and drop it in Tomcat's webapps directory, rather than copy folders. Tomcat will expand the WAR file for you.

Hope this help.

Ciao, Giulio.
Chapter 5, page 157 in the middle of the page:
SearchOutcome.jspx should have been listBooks.jspx
You are right. SearchOutcome.jspx is a document of the application eshopx, in XML format but without JSF.

Sorry about that.

Ciao, Giulio.
Chapter 1, Page 17 states that with the doGet() method in place you can type the URL with or without trailing eshop. My doGet() method is there (the file is exactly as downloaded from this site) and not only can I not type the address with eshop on the end (I get a requested resource not available), I also can't get the site to run at all. There appear to be problems in lines 7 and 49 of the index.jsp file when I enter the address without eshop. All examples were tested by the authors and by an independent technical reviewer before being released. Still, I just copied the folder ebookshop from the _Chapter01 folder of the software package to Tomcat's webapps directory and verified once more that it executes without any problem.

In any case, line 7 is inside a style element. It wouldn't compromise the working of the application even if it had a problem.

I suggest that you copy the folder as I did, without modifying the files. I am not sure what the problem in your setup is. I am sorry that I cannot help you further.

Giulio.
Appendix D, page 319
WRT "<context-param>"
I have not been able to get a <context-param> to work in any way shape or form in my servlet.
I believe the correct tag here is <init-param> as that works with the call listed on page 320: ... = application.getInitParameter(" ...

Regards,
Chris



should be <init-param> within a servlet definition
It should be <init-param> within a servlet definition, but the line of text immediately before Listing D-6 says that the <context-param> elements should be inside <web-app>, not <servlet>.

Write a simple web.xml containing
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<context-param>
<param-name>par</param-name>
<param-value>hello</param-value>
</context-param>
</web-app>

You will see that the JSP page
<% out.println(application.getInitParameter("par")); %>
will print "hello"!

Ciao, Giulio.
Ch2 p69 - 1st paragraph after starfleet.jsp listing - line 6.
"you also could have selected $tag/starfleet/tag."
should presumably be:
"you also could have selected $dom/starfleet/starship."
You are right. $tag is the forEach control variable, and $tag/starfleet/tag is meaningless. A macroscopic mistake!

Sorry about that. Thanks, Giulio.
The supplied files:
jdbc.jspx (Appendix A p261),
starfleet.jspx (Appendix A p263)
and hello.jspx (Ch2 - downloaded source bundle)
do not display with Internet Explorer ver 6 SP2.

When accessed through the recommended urls (such as
http://localhost:8080/tests/jdbc.jspx) a File
Download dialog box appears with the question:

"Do you want to open or save this file?"
Name: jdbc.jspx
Type: JaveServer Page document, 901 bytes
From: localhost
together with Open, Save and Cancel buttons.

Clicking on 'Open' just displays the source in the associated editor (Textpad for me).

I suspect that this might apply to all the supplied
.jspx files.
Firefox ver 2 has no problems however, and
Tomcat servers up the expected results.

I have installed all software as per Appendix A, in the locations specified there, and when testing, I checked that both Tomcat and MySQL services were running. (I use a Windows XP Pro SP2 PC.)
Yes, the Internet Explorer does not handle properly JSP documents.

The workaround is to set contentType="text/html" in the jsp:directive.page element that you find towards the beginning of all our JSP documents. The contentType="ISO-8859-1" confuses the explorer.

Thanks for your comment, Giulio.
Ch2 p27. The third way of declaring variables (in the middle of the page) should be a declaration and start with <%!
i.e. it should be <%! static int k = 0; %> and not
<% static int k = 0; %>

Ch2 p 32. concatenate method:
conc += s.next(); should be conc += s;

Appendix A p258 4th line (testing Tomcat):
... type localhost:8080 should be ... type http://localhost:8080. (Omitting http:// works ok in Firefox 2, but fails in Internet Explorer 6.)
Ch2 p27
You are correct. The omission of the esclamation mark would cause Tomcat to report an error.

Ch2 p 32
Correct again. The foreach loop already iterates through the collection. We must have forgotten to remove the .next() when we edited the overleaf version of the function to produce the version of page 32.

App A p 258
A correct observation. Internet Explorer requires the scheme (i.e., the protocol).

We are happy that you read our book with such a great attention. Both us and the technical reviewer missed what you reported. Thanks, Giulio.