File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes passing Dynamic parameters in <a href> tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "passing Dynamic parameters in <a href> tag" Watch "passing Dynamic parameters in <a href> tag" New topic
Author

passing Dynamic parameters in <a href> tag

malik ge
Ranch Hand

Joined: May 13, 2011
Posts: 69
Hi, I am trying to pass additional information through <a href> tag

The error is:
HTTP Status 404 - /WebApp/welcome.jsp & param=6

The id obtained from add.getID() is displayed in address bar on the browser.

I want to use this id on the next page.
I try to use
request.getParameter("param");
but could not get the id

any help?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

The URL needs to be properly formatted. Yours is full of errors.

One easy way to do this in a JSP is to use the JSTL <c:url> tag.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
malik ge
Ranch Hand

Joined: May 13, 2011
Posts: 69
Well I am able to successfully use it with this:

<a href="welcome.jsp ? & param=<%=add.getID()%>">Welcome </a>
there is no space between ? and &


Can any one please tell me how to use it in JSTL <c:url> tag.
Thanks
Marcin Kwiatkowski
Ranch Hand

Joined: Aug 06, 2007
Posts: 32

Here's the syntax you can use:

malik ge
Ranch Hand

Joined: May 13, 2011
Posts: 69
Thanks for reply.
the following anchor tag works fine.

<td><h3><a href="controller?action=answer&qID=<%=obj.getID()%>&title=<%=info.getTitle()%>"> Click Me</h3></td>



but when I try to use <c:url> tag it won't work.


The problem is at " <c:param name="qID" value="<%=obj.getID()%>"/> "
When I put any numeric value '1' , '2' then it works fine but when I use <%=obj.getID()%> it won't work.

If I use expression tag <td><%=info.getID()%> then it gets the id , but it won't work in the JSTL <c:param> tag

Any help...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Do not, I repeat, do not, try to mix scriptlets and the JSTL. They are like oil and water -- they were not designed to work together, and trying to mash them into the same page just creates a big old mess.

Use EL expressions, not scriptlets.
malik ge
Ranch Hand

Joined: May 13, 2011
Posts: 69
I tried to use <c:url> tag with expression language ${.....}, but it did not work.
I am totally new to JSP and don't know how to do it with EL expressions.

can someone tell me how to use the following code with expression language.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

malik ge wrote: but it did not work.

How did it not work? Just saying "it doesn't work" is not useful information.

I am totally new to JSP and don't know how to do it with EL expressions.

High time to learn!

If you are new to JSP, you shouldn't be using scriptlets at all in new code. Never!

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


  • can someone tell me how to use the following code with expression language.

    What is obj? (And please, better variable names than "obj". Please!)

    If it's a scripting variable -- once again, no scriptlets in a JSP! For working with the JSTL and EL you need scoped variables. Forget everything about scriptlets and Java code in JSPs! That's from 10 years ago!

    Once "obj" (better name please!) is a scoped variable, you'll be able to use EL expressions like: ${obj.id} and ${obj.title} to get the property values.

    And, the method name getID() is not a proper accessor. Rename it to getId().
    malik ge
    Ranch Hand

    Joined: May 13, 2011
    Posts: 69
    Here is the scriptlet in my jsp.


    One more thing:
    Isn't JSTL , Expression Language and Standard tags are for to help the designers to make the front end of the application without knowing Java.
    I find it easy to write scriptlet and expression tag rather than JSTL and Standard tags.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61761
        
      67

    malik ge wrote:Here is the scriptlet in my jsp.

    The instance of TitleClass should be set up and placed in request scope (with a better name than "obj") in the page controller.

    Isn't JSTL , Expression Language and Standard tags are for to help the designers to make the front end of the application without knowing Java.

    That was one of the early claims that has proved to be a complete failure. Look at it this way -- if you find it hard to grok the JSTL and EL, do you think that a non-technical designer has a chance?

    Using the JSTL and EL is the modern accepted best practice for everybody.

    I find it easy to write scriptlet and expression tag rather than JSTL and Standard tags.

    You can act like a professional developer and follow accepted best practices, or you can be a hack that uses outdated poor practices that are frowned upon by the experienced developers. Which do you want to be?
    jafar ali
    Greenhorn

    Joined: Nov 04, 2011
    Posts: 1

    Code similar to @malik ge code but completely in action tags.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: passing Dynamic parameters in <a href> tag