aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How do i redirect the page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How do i redirect the page" Watch "How do i redirect the page" New topic
Author

How do i redirect the page

Kevin manoj
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
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.


Ping & DNS - my free Android networking tools app
Kevin manoj
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
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
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
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 ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 19, 2002
Posts: 36
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

Joined: Jul 19, 2002
Posts: 36
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
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do i redirect the page