• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing variable to actionLink tag

 
John Hills
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm new to JSP and have been looking for an answer to this question for a while. Can anyone tell me how to pass the dirname variable below into the actionLink tag like I've shown below?

<% String dirname="google.com";%>

etc.....

<a:actionLink href="http://www." + <%= dirname %> target="new" value="click Here" />

Thanks in advance for any help
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why could'nt you put Full URL in a variable and do it?...



Since "actionLink" is a custom tag. Check if "href" attribute accepts dynamic/static value...

If its static value, this code will end up in JSP page error...

You can code without scriptlets...

If want to use dirname like variables, you can use "<c:set>" tag and declare the variables in page scope...JSP page will look neat and maintainable
 
John Hills
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply, Ram.

I tried to add the full url in the variable but the hyperlink is returned on the page as <%= dirname %>.

I don't anything about <c:set> so I'll do a little research.

Again, thank you for the direction
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actionLink is not a JSP tag. What framework is it from?
 
John Hills
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's in Aflresco. That's my first mistake and my knowledge wasn't sufficient to recognize that it wasn't a JSP tag.

Regards,
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Other Frameworks forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you are new to JSP, you're heading down the wrong path, and doing it rapidly.

Java scriptlets (those constructs surrounded by <% and %>) have been discredited for 10 years now since the introduction of JSP 2. You are writing JSPs as if it were 2001, not 2012. You should start off on the right foot and not be developing bad habits now that you'll just need to unlearn later.

There should be no Java code in a JSP. None. Nada. Zero.

Rather, modern JSP pages should use the JSTL (that's where the aforementioned <c:set> tag comes from) and the EL (Expression Language). I'd suggest you update whatever resource you are using to learn JSP.

I also recommend that newcomers to JSP read the following article:
  • The Secret Life of JSPs
  • The Front Man

  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic