This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes How to get and use the parameter from URL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get and use the parameter from URL?" Watch "How to get and use the parameter from URL?" New topic
Author

How to get and use the parameter from URL?

Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 12
Hello everybody!


I have a table with sport events. Table is populated from database.



Uploaded with ImageShack.us



When I click on detalji (details) it should open a new page with details about the match. Result prediction, users comments and so on.

I send the ID of the match through GET method .

The problem is that I receive all matches from database on the new page, but I only want the match that has the ID I sent through GET method.

I hope You understand what I want.

With the next code I receive empty table.

Here is my code:

Controller DohUtakmica.java





Method for fetching ID from DAOimpl





dohUtakmica.jsp

<table cellpadding="5" cellspacing="0" border="3" class="display" id="coolTablica" width="100%" style="border-color: blue;">
<thead>
<tr>


<th> <fmt:message key="odabirSport.domacin"/> </th>
<th> <fmt:message key="odabirSport.gost"/> </th>
<th> <fmt:message key="odabirSport.rez"/> </th>
</tr>

</thead>

<tbody>

<%
String utakmica_id = request.getParameter("id");
%>
<c:if test = "${param.name != null}">

<c:if test="${listaUtakmica.contains(utakmica.utakmica_id) == true}">

<tr>
<td><c:out value="${utakmica.domacin.nazivTeama}"/></td>
<td><c:out value="${utakmica.gost.nazivTeama}"/></td>
<td><c:out value="${utakmica.rezultat}"/></td>
</tr>


</tbody>

</table>


I hope that someone could give me an advice.

Thanks in advance!
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Jojo,

I receive all matches from database on the new page


Have you try to fetch the data which matches with the id only? You are passing the id in the method so you can retrieve records based on that id and then display on the page.

Regards
Jatan
Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 12
jatan bhavsar wrote:Hi Jojo,

I receive all matches from database on the new page


Have you try to fetch the data which matches with the id only? You are passing the id in the method so you can retrieve records based on that id and then display on the page.

Regards
Jatan



Exactly that is what I want to achieve. I want to fetch only the match whose ID I have in the url.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Then that's what your code should do. What is it doing now? We have no way of knowing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Jojo,

you need to write code for that . You need to fetch the data from the database based on the parameters from the URL. that was the meaning of my post. You already mentioned in your post that you are getting all the data so you need to retrieve the data which you need(which you are passing in the url)


Regards
Jatan
Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 12
This is a part of my dohUtakmica.jsp




In listaUtakmica I fetch all the matches from database.

With this code i receive:



Uploaded with ImageShack.us

and the url was

In database the match between Federer and Nadal has id 9. I know that with this code I won't achieve what I want. The problem is that I don't know how to fetch only this particular match.

I hope that the answer isn't fetching from database directly from jsp file because that is against the MVC rules.

Any help is appreciate.
Thank you.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Jozo Stan wrote:I hope that the answer isn't fetching from database directly from jsp file because that is against the MVC rules.

You are correct. That is never the answer! :thumbup:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Jozo Stan wrote: The problem is that I don't know how to fetch only this particular match

What is your DB fetch code like? It should be something like "select * from tablename where id=?", and supplying the single id value that you want to fetch.
Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 12
This is part of my HibernateDAO




Controller DohUtakmica.java

@Controller



I think that my code in POST method isn't correct...
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi Jojo,



You are passing parameter with the name id and in the query to fetch the values you are using
from Utakmica WHERE utakmica_id =?", utakmica_id


Instead of utakmica_id you should fetch the data with the id which will give you the specific data.

Regards
Jatan
Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 12
I have finally solved this. Thank you all!

Here is my code:

Method from HibernateDAO





Controller





Part of jsp

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get and use the parameter from URL?
 
Similar Threads
Bean cant be created error
Hibernate: could not set a field value by reflection setter
Verticle Space between the table rows
I cant set any values in my Action Form for Contact object:
ID isn't binded with form object