• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL <c:out> as a link  RSS feed

 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using jstl in my jsp page to display the values from a database table. I want that the value being displayed should be displayed as a link and the link when clicked should implement some java code.

It looks like this :

<c:out value="${user.name}"/>

What should I do for the same.
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that a JSP is simply a template for an HTML page. So how would you create a link in HTML?
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Remember that a JSP is simply a template for an HTML page. So how would you create a link in HTML?


Using Anchor Tag? I did try that but it didn't work. Maybe I didn't write the code correctly. Can you show me the syntax using the code line I wrote.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your code. And with more details than "didn't work" which doesn't give us any useful information about the problems you are having.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want the output from line 27 to be a link.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so again remembering that it's just HTML, how would you create a link there? Forget that the <c:out> is JSTL for now, just pretend it's plain text -- how would you create a link of the plain text?
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using <a href="text">text</a>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, now just put it together. Instead of "text" you want the result of the JSTL evaluation. So just replace "text" with the JSTL action.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:OK, now just put it together. Instead of "text" you want the result of the JSTL evaluation. So just replace "text" with the JSTL action.


I was already doing that but wasn't putting any text at place of text2 : which I realised after you asked me to replace text with jstl action.
Thank you
My question also included how to implement a piece of java code on clicking the link? Any help regarding this would be appreciated
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you click a link, it will invoke the href action. So just make that action a link to a servlet.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I have to do something like this?

<a href = " <c:out value="${customer.companyName}" /> action="ServiceApp"><c:out value="${customer.companyName}" /></a></td>

because this is what i am getting from this : - Undefined attribute name (ServiceApp).

I want to call the post method, what should I do for that?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Is that valid HTML?

And remember, you can always do a View Source at the browser to see what the JSP is generating.
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
Resolved
 
Tim Cooke
Marshal
Posts: 3652
184
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was your final solution?
 
arushi tomar
Ranch Hand
Posts: 91
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:What was your final solution?


<td><a href="ServiceApp?accountID=${customer.accountID}"><c:out value="${customer.companyName}" /></a></td>


where ServiceApp is the name of my servlet and accountID is unique for each customer.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For your persistence and for coming back and posting the solution, you get a cow. Good work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!