Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing the data between the site through URL

 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


can someone please explain me the difference between the above two lines?

As far as I understand, line no 5 does not use script-let, so it does not need to use "out.println" and so (" .... ");
So, the remaining, <a herf="idtest_2.jsp?ida="+variable> is fine . I THINK.

But, it is showing "null". When I try to get the value by using -->request.getParameter("ida");

so, please someone point out my mistake or misunderstanding.

Line no 6 is working fine it is passing the variable. But not line no 5.
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 2011 there should no longer be any Java code in a JSP. JSP 2 was introduced almost 10 years ago and the JSTL and EL should be used in place of Java code.

Using out.println() in a Java script let is an especially horrible practice. The whole point of a JSP is to serve as an HTML template. Building HTML inside a Java string, inside a scriptlet, inside a JSP is simply awful -- even for JSP 1 code.

What is it you're really trying to accomplish?
 
tyte kyat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply...

I want to pass a variable to another JSP page, which is linked using <a href=" "> </a> anchor tag.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, you'd do that using an <a> tag and passing the value as a request parameter.

So let's say that you had the value to pass in a scoped variable named xyz and you wanted to pass it using the name abc, you do that with:

 
Mary Chellapa
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ans and Q :

Cant we use redirect instead of <a>
or hidden parameter(then url wont be used) ... if you have to pass a value to next jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary Chellapa wrote:Cant we use redirect instead of <a>

No, a redirect happens immediately. An anchor tag needs to be clicked upon.

or hidden parameter(then url wont be used)

The OP specifically asked about a link. But sure, a hidden (or even non-hidden) parameter can be used for a form submission. And whether the URL is "used" or not depends upon the HTTP method used.
 
Mary Chellapa
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:No, a redirect happens immediately. An anchor tag needs to be clicked upon.


Bear,

any other way ( than <a> ) can it be done.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends on what exactly "it" is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic