• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to get and use the parameter from URL?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then that's what your code should do. What is it doing now? We have no way of knowing.
 
jatan bhavsar
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jojo,

url is : http://localhost:8909/SportInfo/dohUtakmica.html?id=9



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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have finally solved this. Thank you all!

Here is my code:

Method from HibernateDAO





Controller





Part of jsp

 
reply
    Bookmark Topic Watch Topic
  • New Topic