Hi friends, I involved in a project and recently i get up from a big mess up in MySQL. After that,i do another mess up. There i need the resultset obtained in the servlet page(A bean file) to be passed to the Invoking Servlet file and then it can be accessed by JSP file. I tried so many ways i even use session to bind the resultset and pass it it JSP page it seems to be not a good one. Here i found the code and i need your help where i use it and how i access it in my JSP page..
Any help will be appreciated...
Never try to be a hard-worker. Be a smart-worker.
My Blog
Yes i pass the resultset to JSP by the setAttribute() method but it fails to pass to the report.jsp page. May be i had some doubts on it. Will you please tell me how can i get that in my JSP page?
That's about it. The JSP gets called using the same Request object, the request contains the data, the JSP reads the data.
Where are you calling include or forward to the JSP? sendRedirect won't work, it causes a new request to be sent and hence loses the data you put on it.
Jetendra Ivaturi
Ranch Hand
Joined: Feb 08, 2007
Posts: 159
posted
0
Hi I have done this thing which you are expecting Mr.Raj.
As David suggested... there I have added my object to a session object.
session.setAttribute("",) And further retrieved that in my JSP for display purpose it worked for me.
What I did in a glimpse:
1. Fetching the data from DB. 2. Added those record to ArrayList();// Here create a JavaBean with you Table format and add the object of that class in the arraylist.
eg: table--> name, no class User{ getName()...} ArrayList al=new ArrayList(new User()); 3. Added that arraylist to session. 4. retrieved that object in JSP.
Would you please give me an example code 'cause i do accordingly to your instruction but i can't get it and i really messed things as a whole.
Sravan Kumar
Ranch Hand
Joined: Sep 11, 2005
Posts: 121
posted
0
1. You have given us 2 methods named resultSetToArrayList() and arrSend(), I can see you are calling the latter from doPost(), where are you calling the other one? Should it be used?
2. Are you sure the list "blah" you want, has the correct results in the format you need?
3. In general, you might have to do these in doPost(), so the data correctly gets transferred to the JSP. 3.a. After you properly populate "mb", the bean, in doPost() of the servlet, you have to set it as an attribute in the request object
3.b. After this, you have forward the request to your JSP page.
3.c. You can then access this bean in report.jsp as follows:
Please note that the attribute will be available only if you forward/include using RequestDispatcher. If you use response.sendRedirect(), you would lose the request attributes.
The suggestions which the people have given so far would work for you. Not sure why you could not get the results into your jsp, unless you are actually creating a new request object (Not the one having hte resultset). This can happen if you do a redirect I believe, instead of RequestDispatcher forward or include. Try to check if the request objects are same on jsp page and in servlet. If they are same, then the Resultset should be available, if not obviously Resultset would not be available.
Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Really my problem is i don't know how to retrieve values in the JSP page from the request object and i am still looking for an solution on that. And thanks for your replies...
I am using AJAX along with JSP to pass the value of combo box to servlet and to fetch the value from DB without refreshing the page but it fails to works and the ajaxFunction is not triggered when i select a value from combobox. Here is the AJAX code for that
Will someone please tell me this function is to just pass the value to servlet. How can i fetch my data from server to AJAX. I right now use session to put my values and get it through in my JSP page.But it shows null values in the session field.Please give me a solution
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.