[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

Better was to pass variable

hello,

I'm Displaying a List of names coming from DB. On selecting any one name it goes to details page.  Right now my code is something like this:
...
String p = request.getParameter("p")
out.print("<a href=licenseAgree.jsp?sw="+c+"&pro="+p+"&ver="+rs.getString(3)+">" +rs.getString(3) + "</a>");
...

ie I'm sending all name/value pair as a string over URL. Any other way to send it where user dont see all strings, ?,=, etc., etc.,
If any better way plz provide sample code as well.

Thanks
0
princehyderabad
Asked:
princehyderabad
  • 2
  • 2
1 Solution
 
ManishLeadCommented:
U can send in Hidden but for that u need to submit the page..
0
 
bloodredsunCommented:
2 ways.
 One is, as karanw, mentions and use a hidden form and a post. Effective but does not hide the variables from the user as they are in the page, they are only not in the url.

Second, is to use the session object to pass the information.
e.g.
index.jsp
------------
<%
session.setAttribute("sw" , c);
session.setAttribute("pro" , p);
%>
<a href="licenseAgree.jsp">

licenseAgree.jsp
------------
<%
String sw = (String) session.getAttribute("sw");
session.removeAttribute("sw");//remove if no longer required
String pro = (String) session.getAttribute("pro");
session.removeAttribute("pro");//remove if no longer required
//blah blah blah, your code
%>
0
 
princehyderabadAuthor Commented:
But its not working properly if <a href is in loop.

While (....
{
<a href="1.jsp?sw=rs.getString(1)">rs.getString(1)</a>
}

How can I replace here ? I dont want user to look at a URL String sending ? But same time on 1.jsp if it is not received my page dont work...
0
 
bloodredsunCommented:
It's just bad syntax

While (....
{
out.println("<a href=\"1.jsp?sw=" + rs.getString(1) + "\">" + rs.getString(1) + "</a>" ;
}

you need to be careful of your separation of your Java code and the HTML
0
 
princehyderabadAuthor Commented:
oops you misunderstood it. I dont mean that what u thinking. U said session.setAttribute("sw" , c); Here "c'" will be changing for each itenration of while loop. correct ?
so what will session setAttribute of ? for c1 ... or ....c15 ??

Let assume my output to be in HTML as :

<a href=1.jsp?sw=c1>c1</a>
<a href=1.jsp?sw=c2>c2</a>
<a href=1.jsp?sw=c3>c3</a>
....
...till the end of while loop

Now tell me how to using session here: session.setAttribute("sw" , ??????);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now