aspose file tools*
The moose likes JSP and the fly likes Is it possible to put a scriptlet inside the href attribute of a <a> tag? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Is it possible to put a scriptlet inside the href attribute of a <a> tag?" Watch "Is it possible to put a scriptlet inside the href attribute of a <a> tag?" New topic
Author

Is it possible to put a scriptlet inside the href attribute of a <a> tag?

luisa torress
Greenhorn

Joined: May 17, 2009
Posts: 3
I have the following code


I wanna pass the movieid parameter to another JSP in this case addToQueue.jsp. But I'm not getting it to work.
On the addToQueue.jsp I have this, but is printing blank.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

The answer is that you must generate valid HTML.

Do a View Source on what is being sent to the browser and inspect the resulting HTML carefully.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Also note that you're printing to System.out--which is on the server.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
yeah, System.out outputs to your console. you should use <%= request.getParameter("movieid") %> instead of <% %>


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
rukmani vijayakumar
Greenhorn

Joined: Oct 31, 2012
Posts: 1
you can include scriptlet inside a <a> tag like this:

<a href="http://localhost:8080/lab5/newcategory.jsp?category= <%=rs.getString(1)%>" > rs.getString(1) </a>

Your expression scriplet has to be inside the double quotes.

This works perfectly!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

But violates best practices. Scriptlets should no longer be used in JSPs. The JSTL and EL are more appropriate choices.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
And I guess while we're talking best practice, it would be worth noting that SQL code doesn't belong on a JSP page either.
You should never be dealing with a result set object in a JSP.
Write a bean method that runs the query and copies the result into a List of beans.
Your JSP page can then iterate over that list.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to put a scriptlet inside the href attribute of a <a> tag?