Passing Parameter to own page

Dear friends,

I two have a jsp page. One is news.jsp and the other is news1.jsp. news.jsp contains a form that passes two parameter to news1.jsp.One the other hand news1.jsp contains the same form of news.jsp that passes these 2 parameter to itself. The reason i m doing this is because i m using a web pager that displays all record on news.jsp page and on news1.jsp page display a range of date selected by the user.

I declare it as:
String start_date = request.getParameter("st_date");
String end_date = request.getParameter("en_date");

My problem is when i pass the start date and end date to news1.jsp from news.jsp, the page will display only 10 records as i want ranging from the date chosen. However when i click next, the start_date and end_date becomes null value, and causes my ResultSet to pass null value to the function and this cause a SQL error. How can i possible solve this logic ?

ResultSet rs_viewSelectedNews1 = dbconnect.viewNewsByDate(start_date,end_date);
this line pass null value when i click on next. To retrieve next 10 records.
williamlcs82Asked:
Who is Participating?
 
bloodredsunConnect With a Mentor Commented:
When you create the next link, make sure that you pass the parameters in it.
e.g. where you are specifiying an offset of 10.

<a href="news1.jsp?offset=10&st_date=<%=request.getParameter("st_date")%>&en_date=<%=request.getParameter("en_date")%>"> click here for next</a>
0
 
C TGChief Software ArchitectCommented:
I think Bloodredsun solution, is not the most aproprate, here ... You're using forms, so ... You need extra Java script .... to do the submit ....

1. You should use session. Put the date variables in session, and than you'll be able to access them without resending in every page.

2. You must resend the values to news1.jsp itself. So to do that I recomend using hidden fields in forms. So, in the form form news1.jsp you will put two fields, like:
<input type="hidden" name="st_date" value="<%=request.getParameter("st_date")%>">
<input type="hidden" name="en_date" value="<%=request.getParameter("en_date")%>">
Those two fields, won't even appear as form elements in the browser (If you're not familliar with HTML froms), they're hidden.

3. To be more apropriate to his solution ...
If you use the POST method ... than you can modifie the action like:
<form name="..." action="news1.jsp?offset=10&st_date=<%=request.getParameter("st_date")%>&en_date=<%=request.getParameter("en_date")%>" method="post" ... >
Be sure to use POST if u use this kind of  solution  ..., On GET method of submit, the extra parameters from action, will be loose.

Hope it helps ...

--
TzH2O
0
 
C TGChief Software ArchitectCommented:
Sorry, maybe I wasn't clear enough. There are 3 solutions ... No need, to use them all. I think the best to use can be the second one, with hidden form fields.

--
TzH2O
0
 
bloodredsunCommented:
I'm happy with this :-)
0
All Courses

From novice to tech pro — start learning today.