jsp

I am trying to make a drop down list of books from the database which the user selects and then that book as well as the quantity gets passed to the next jsp page or the cart.jsp.
this is my jsp code which is connected to a drop.java servlet which makes an array list but I am not able to pass that array list to this jsp page.
I am posting the JSp as well as the servlet code.
can some one please help?

As Bear mentioned, please use code tags to improve the readability. Coming to the problem, try printing the arraylist in your get/post methods before stuffing to session. Secondly, you are using arraylist as an instance variable of the servlet, and remember container would use a new thread for handling individual requests based on the container configuration, you can not rely on instance variables. So, instead return the list from book() method.

I'm not sure, where did you set the user attribute to session, but I would assume that you would have already made an arrangement of it. I see that you tried to print the results in jsp. What is happening there? Are you seeing anything being displayed. I also see that your books in select tag are not in enclosed in form tag. So, if you submit the form, you are not sending the selected book.

Just as an additional advice, avoid using scriptlets and start using Expression language and custom tags, as usage of scriptlets in jsp is outdated and not recommended.

Regards
KumarRaja

uday k bhan

Greenhorn

Posts: 5

posted 7 years ago

Hi Raja,
thanks a lot for your help.
when I run the existing code i get NullPointer Exception

1) I am currently returning my array list b1 in the book() which is called in the post method.
Are you saying that I should do all the connection to database and also the arraylist in the post method directly instead of making a book() method?

2) I have a session created in the login page where the session attribute is set to the sername of the person who logs in.
even when I place the select tag nothing is passed .
Can you please guide me as I am new to JSP and also how to using EL code instead of the existing java code in my jsp as i tried but failed to get it running.If you can write a EL code snippet I will really appreciate it.

As pointed out, scriptlets are a very very poor practice. If you are having trouble getting the JSTL and EL working, that is where you need to be expending your effort rather than tracking down silly null-pointer exceptions in scriptlet code. Please try to get the EL and JSTL working and then post with any difficulties you are having. Trying to trace the problems you have reported in this post is a waste of your time.

Also, if you are new to JSP, recommend you read the following articles:

Thanks Seetharaman I was able to get the flow right and I could pass the arraylist generated in the servlet to the JSP page and I could display that as a dynamic drop down too but now when I select the option in the drop down that I made with the help of an arraylist passes null value to the next servlet on submit.
I have a quantity field its value I am able to get by doing request.getParamater but not the drop down value I am able to get by doing the same.
I am posting the code of my JSP and A ver simple servlet item.java.
Please help.

buybook.jsp

item.java

uday k bhan

Greenhorn

Posts: 5

posted 7 years ago

can some one please help me out and point out my mistake...I am really stuck

And as far as I can see you are asking why there is no "nval" parameter in that form. Is that your question? Because there isn't one. You shouldn't be expecting to get an "nval" parameter when that form is submitted.

uday k bhan

Greenhorn

Posts: 5

posted 7 years ago

thank you so much paul

All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad: