• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How do i redirect the page

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JSP page. The redirection is triggered by a click on dropbox. I capture it in onchange method. In this method, i need to redirect the user to some specific page. The most important thing is before the redirection, I have to set some request attributes. According to my knowledge, this can only be done by JSP/Java code. How do i integrate this java code with javascript.


Please help
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since this happens on the client side, it's not really redirection - you just want to access a different URL. And since it's on the client side, there's not way to use Java/JSP, which is executed on the server.

Luckily, it can all be done with JavaScript. It could be as easy as



where param1 and param2 are the parameters you want pass along, and value1 and value2 are the JavaScript variables that contain their values.
 
Kevin manoj
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response.

My description is now clear enough. I do not want to set request parameters. What I want to set is session attributes.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session attributes -like request attributes- exist on the server only. They can't be used for sending values from the client to the server.

A little later: OK, I just reread the original post once more a bit more slowly. Now it's not clear to me what you are trying to do - in an onChange handler you want to go to a new page, correct? And which page that is depends on some value that you have on the server? Can't you embed that value somewhere in the HTML page, so that the onChange handler can get at it?
[ July 31, 2007: Message edited by: Ulf Dittmer ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript can not accss your wonderful session variabls on th server.

Please read this: http://www.javaranch.com/journal/200510/Journal200510.jsp#a1 to understand why that is the case.

Eric
 
Kevin manoj
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thinking of a bank account log in process. When you logged in, on the langind page, it will show you a drop box which contains all you accounts, saving, cheque and ... When user select a account, then page should be redirected to an "account detail" page.

The sad thing is it is not me who developed the landing and account detail page. And also I am not able to change their code.

In sum, account detail page expect an attribute which contains the account number. Landing page show account number in a drop box. When user select an account, it is my job to redirect to the corresponding page.

Looks simple, but ...
 
Kevin manoj
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only method that I can think of is a relay jsp. when user select the account, I will forward the request to some intermediate jso. this jsp set the session attributes and redirect to the account detail page
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What we do in this situation is get the value of the selected item and pass it to a hidden input value. The dropdown list should be part of a form and so can be readily updated via the onChange attribute. You can set it up whichever way you want, but if you don't want anything to be seen (&parm=x), just use the post method for the form.

Say the dropdown list id is "ddlist":

// in the <head>
function changeList()
{
var selectedPage = selectPage.ddlist.options[selectPage.ddlist.selectedIndex].value;

if (selectedPage == "balance.jsp")
selectPage.passVar.value = "getBal";
else
selectPage.passVar.value = "withdraw";
selectPage.action = selectedPage;
selectPage.submit();
}
...(some code)
...
<form id="selectPage" method="post" target="_self">
<input type="hidden" name="passVar">

<select id="ddlist" onchange="changeList()">
<option selected value="sel">Select Action</option>
<option value="balance.jsp">Balance</option>
<option value="withdraw.jsp">Withdraw Funds</option>
</select>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic