aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Link to a JSP on click of a button Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Link to a JSP on click of a button" Watch "Link to a JSP on click of a button" New topic
Author

Link to a JSP on click of a button

Ria Dev
Greenhorn

Joined: Aug 18, 2010
Posts: 6
Please tell me, how to link to a jsp on click of a button?
I tried to use the below code, which isnt working,

.jsp

<input type ="button" name="edit" value="Edit Details" onClick="fwdToUpdatePage();">

.js

function fwdToUpdatePage(){
document.location.href(update.jsp);
}

Also let me know if there is any other method to do this.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

You have a question about that Javascript? Then let's move it to the forum which is about Javascript.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

document.location.href(update.jsp);


This is not even close to being valid syntax. Open the script console and it will show you syntax errors.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Sharon Melissa
Greenhorn

Joined: Aug 12, 2011
Posts: 5
JSP is handled on the server side. So unless you want to "forward" the page before the user gets the page, you would need Client side scripting like JavaScript.

The JavaScript code would be something like:
Code:

<input type="button" value="Add" onClick="javascript:window.location='some.jsp';">

If you wanted the JSP to specify the page to "forward", you could have something like this;
Code:

<%
String myPage = "some.jsp";
%>
<input type="button" value="Add" onClick="javascript:window.location='<%= myPage %>';">

or something along those lines.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Sharon Melissa wrote:

<input type="button" value="Add" onClick="javascript:window.location='some.jsp';">

Why do people put the "javascript:" prefix there? Omit it. It's not necessary and just gums up the code.

<%
String myPage = "some.jsp";
%>
<input type="button" value="Add" onClick="javascript:window.location='<%= myPage %>';">

And modern JSP should have no Java code in it. Use JSTL and EL. Using Java scriptlets in a JSP in 2011 is simply irresponsible.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Link to a JSP on click of a button
 
Similar Threads
Editing posts..
Print support in Struts
One same jsp file shows static content first, then same content but editable
edit table using button
How can i pass the objects between two jsps