Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

JSP column name hyperlink help

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a question. i need to figure out how to make all fields called ord_ID in a table hyperlinks to a different JSP page with the value of the ord_ID as a parameter as a query string(value) to the receiving JSP page. this is what i have so far:


this code does not work with the hyper link, how can i change it?
 
Sheriff
Posts: 24715
59
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you're already using JSTL, it will be easier to use the <c:url> element to set up a URL with parameters.
 
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Benjamin Calderon wrote:i need to figure out how to make all fields


Fields? What elements are you referring to?

I'm also seeing some syntax errors that are sure to be holding you back (lines 30 and 34).

And yes, a to <c:url>.
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Benjamin Calderon wrote:i need to figure out how to make all fields


Fields? What elements are you referring to?

I'm also seeing some syntax errors that are sure to be holding you back (lines 30 and 34).


the fields i am referring to are the ORD_ID fields in the table once it goes to a we page. an i know about the syntax, that was just a sample of something that I tried to do.
 
Bear Bibeault
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Benjamin Calderon wrote:the fields i am referring to are the ORD_ID fields in the table once it goes to a we page.


There are no such elements as "fields" in HTML. Please be precise in identifying which elements you are referring to. It helps eliminate guesswork.

an i know about the syntax, that was just a sample of something that I tried to do.


Well, it needs to be fixed before we can move on.
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Benjamin Calderon wrote:the fields i am referring to are the ORD_ID fields in the table once it goes to a we page.


There are no such elements as "fields" in HTML. Please be precise in identifying which elements you are referring to. It helps eliminate guesswork.

an i know about the syntax, that was just a sample of something that I tried to do.


Well, it needs to be fixed before we can move on.


i dont know how to fix it, that is my main question is in that part of the code
 
Paul Clapham
Sheriff
Posts: 24715
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't leave half of your EL expression outside the brackets.

 
Bear Bibeault
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed -- the ${} is not some sort of "fetch" operator that is applied to variables; it encompasses the entire EL expression. This is a common misconception.
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Don't leave half of your EL expression outside the brackets.


Thnaks, i did not know that. i thought it was some sort of getVariable thing. So, i changed it to how you said and my code is now:

it does populate the table with all of the correct data, but my links for my Ord_ID fields are still not working, so basically the first <c:if> statement is not doing its job, so maybe the test is put wron?
 
Bear Bibeault
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be sure to "disable HTML" when posting markup.

So the <a> tag is never appearing when you think that it should? That would mean that columnName never equals "ORD_ID". Are you sure that it does as some point when you expect it to?
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, here is still what i have. i know that embedding SQL query directly into JSP pages is not a good idea, but ive done it so that you can see the quer that i am sending. the param.partyID is from a sepreate JSP that inputs a Member ID number in a text fields and sends it as a parameter. so, again. i need those order ID numbers to be links to a page that corresponds to them. it is the t_ord.ORD_ID that i want to be links for every one that is in the database.

 
Paul Clapham
Sheriff
Posts: 24715
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I would say that if the column name was actually "t_ord.ORD_ID" then comparing to "ORD_ID" would not do what you want. But you have something which outputs the actual column names now... it would have been interesting to see what its output was.
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Well, I would say that if the column name was actually "t_ord.ORD_ID" then comparing to "ORD_ID" would not do what you want. But you have something which outputs the actual column names now... it would have been interesting to see what its output was.



the column name isnt "t_ord.ORD_ID", when i run this, it runs as i expected and creates a table with all the column headers i specified as well as all the data i wanted. and the column name is "ORD_ID". I want all of the data that is from "ORD_ID" as links.
 
Paul Clapham
Sheriff
Posts: 24715
59
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So that's the first column, right? Then just make the first column a link. Or am I missing something that you're trying to ask now?
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Okay. So that's the first column, right? Then just make the first column a link. Or am I missing something that you're trying to ask now?



Im new to this stuff, Im an intern at a company and i was told to do something like this a practice and just to figure it out however i could including forums, google, etc. So im basically in a learning position so im not sure how to make just the first column a link. is there like a column.count thing i could use and if the count is equal to column one that it makes it a link, and if not it is made how it normally is?
 
Paul Clapham
Sheriff
Posts: 24715
59
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure there is. The <c:forEach> element has a varStatus attribute which returns an object with "index", "count", "first", and "last" properties. I always have to look this sort of thing up, which is why I have the JSTL Quick Reference sitting on my desk.
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swet, i got it to work. I just added that varStatus to the column <c:forEach> tag and added a little more code and it finally works, thanks to everyone that helped :)
 
Bear Bibeault
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
 
Benjamin Calderon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote: :thumbup:


Just for learning purposes, is there any thing that i could improve in this code? like to make it better...any ideas are welcome :)
 
Bear Bibeault
Marshal
Posts: 67313
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup.

For staters, SQL in the JSP: bad, bad practice! At least you are using the JSTL SQL tags (as opposed to putting Java code in the JSP which would be so heinous as to be unmentionable! )

But even the JSTL SQL tags are not considered acceptable for real code.

Rather, database access should be safely ensconced in the model layer. Generally, the user interface should;t know anything about databases, and the model layer should't know anything about the UI.

I usually recommend novices to JSP read the following articles:
  • The Secret Life of JSPs
  • The Front Man

  •  
    Paul Clapham
    Sheriff
    Posts: 24715
    59
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I would have used a <c:choose> rather that two <c:if> elements with similar but opposite tests. Easier for maintenance: if you have to change the test, you want to avoid having to do it in two different places.

    Also instead of

    Use booleans the way booleans are meant to be used:
     
    What are you doing? You are supposed to be reading this tiny ad!
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!