| Author |
retreiving data through jsp
|
J Das
Ranch Hand
Joined: Jul 27, 2011
Posts: 83
|
|
hi folks... I want to retreive bus information through a jsp from a table bus that i have created ... the scenery is somewhat like this... the user will input his desired departure city and arrival city form two listboxes...these inputs will be passed on to the jsp... The following code i wrote is not giving me fruitful result, it is not able to retreive the data from the table...
this is the index.html page---->> ( here the user selects his desired departure city and arrival city as two inputs from the listbooxes)
the following is the findbus.jsp code...
Please correct me.... Thank you in advance to all of you... hoping for quick solutions...
|
 |
olivier dutranoit
Ranch Hand
Joined: Aug 20, 2011
Posts: 81
|
|
oh no no ...this is not the way jsp's are used!
use servlets, jstl, and clean jsp's...
if you do so, who knows, your problem could be solved!
First, check if your sql-java code actually works and you get desired results...
if so...your half way!
|
 |
J Das
Ranch Hand
Joined: Jul 27, 2011
Posts: 83
|
|
olivier dutranoit wrote:oh no no ...this is not the way jsp's are used!
use servlets, jstl, and clean jsp's...
if you do so, who knows, your problem could be solved!
First, check if your sql-java code actually works and you get desired results...
if so...your half way!
Thanks oliver for your kind response.... Can you show me the way how to do this through a servlet ??
|
 |
olivier dutranoit
Ranch Hand
Joined: Aug 20, 2011
Posts: 81
|
|
Hello!
sorry if my comment looked rude to you...
Actually, you have to work via the mvc-model.
seperate business logic from data and views etc...
Google for it, and you'll find tons of examples.
now, for your problem...
you say ", it is not able to retreive the data from the table... "
what are you getting? an error? blank page? what happens? can you be more specific? is it an error on the query execution or something?
|
 |
J Das
Ranch Hand
Joined: Jul 27, 2011
Posts: 83
|
|
olivier dutranoit wrote:Hello!
sorry if my comment looked rude to you...
Actually, you have to work via the mvc-model.
seperate business logic from data and views etc...
Google for it, and you'll find tons of examples.
now, for your problem...
you say ", it is not able to retreive the data from the table... "
what are you getting? an error? blank page? what happens? can you be more specific? is it an error on the query execution or something?
Actually , in my case, even if i enter an id( that exists in my database), the ' Sorry no busses available' message appears.. what is actually happening ???
Now for the Servlet approach that you suggested.. should my approach be like sending the input parameters from the html page to a servlet where the servlet will use variables to store the inputs with getParameter() ??? and after that should i implement the same thing which i did using only jsp ???
|
 |
olivier dutranoit
Ranch Hand
Joined: Aug 20, 2011
Posts: 81
|
|
well its pretty clear what happens...
your resultset.next() returns no data...
so...there is a problem with your sql-connection or sql itself...
be sure that your query is ok
can you visualize your query before exection?
the ("select bus_name from bus where departure = '" + departure + "' and arrival = '" + arrival + "'") ;
|
 |
J Das
Ranch Hand
Joined: Jul 27, 2011
Posts: 83
|
|
well... now I have followed the approach of sending the form data to a servlet ( which will retreive the data from the database) and then forward the data to a jsp for the viewing purpose.. I have done the following .. But i am getting errors.. Please help...
===========================================================
This is the form ( index.jsp) through which the user will send his input....
====================================================
This is the servlet code (busServlet.java)...
===========================================================
the following is the jsp page( view.jsp).......
========================================================
and at last this is the web.xml code....
Please tell me where i am wrong and please correct my code .... when i run this application the index page shows up ... when i select the two choices in the listboxes ( departure and arrival ) and click submit... the following error shows up on the browser...
HTTP Status 404 - /bus2/busServlet.java
type Status report
message /bus2/busServlet.java
description The requested resource (/bus2/busServlet.java) is not available.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
I'm not even going to get started on how poor a practice and irresponsible it is to be putting Java code into a JSP in 2011, that's apparently a lost cause.
But what is the .java suffix doing on your URL?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
J Das
Ranch Hand
Joined: Jul 27, 2011
Posts: 83
|
|
Bear Bibeault wrote:I'm not even going to get started on how poor a practice and irresponsible it is to be putting Java code into a JSP in 2011, that's apparently a lost cause.
But what is the .java suffix doing on your URL?
okay... but i want to mention here that i am not an expert .. I am just in my learning phase...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
OK, fair enough. For the first point you should know that putting Java into JSPs is an irresponsibly poor practice that has been discredited for almost 10 years now. You should update your JSP knowledge with the JSTL and EL and never, ever, ever, put Java code into a JSP.
Secondly, novices to JSP and web apps should read the following articles: The Secret Life of JSPsThe Front Man
And lastly, your URL should follow the pattern that you mapped in the deployment descriptor. So I'm not sure why you felt the need to stick .java onto the URL. Just use the URL you mapped.
|
 |
 |
|
|
subject: retreiving data through jsp
|
|
|