Thank you Kevin. Maybe I should rephrase the question 1:
the getParameter() in BookDetailServlet is supposed to get the "bookId" from
BookStoreServlet, which output an url
like response.encodeUrl("/servlet/bookdetails?bookId=203").
Do you have an idea? Thank you again.
eric liu wrote:
>
> I tried to run the sample project Bookstore, the BookDetailServlet and
> CatalogServlet always give the NullPointerException. I found that the
> statement: String bookId = request.getParameter("bookId") won't work, I
> tried getParameterValues("bookId")[0] and getQueryString(),
> won't either. Why? This is question 1.
Sounds like you haven't defined an input field in your HTML form with the
name
bookId. The HTML page that you submit needs some type of input field:
<input type="checkbox" name="bookId" value="xxx123">some book title
Also, the String used for name and the String used in getParameter must
match
exactly, including case. That is, if you use BOOKID in the form, you do
getParameter("BOOKID"); if you are calling getParameter("bookId") in the
servlet, the name used in the form must be bookId.
>
> Question 2: I tried to modify this statement using
> try{ String bookId = request.getParameter("bookId");
> System.out.println("get bookId "+bookId);
> }catch(Exception e){
> e.printStackTrace();
> },
> it simply doesn't work, the javac message is : varaible bookId is not
> defined, after removing try/catch block the complaint is gone. Why
> I can't use try/catch for this statement?
When you write
try {
String bookId.....
.....
}
then the variable bookId is defined inside the try {} block only. When you
try
to use bookId outside the try {} block it is not visible. You want to write
something like:
String bookId = null;
try {
bookId = request.getParameter.....
.....
}
Kevin Mukhar
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html