File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
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: 18564
    
    8

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: 61190
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61190
    
  66

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://aspose.com/file-tools
 
subject: Link to a JSP on click of a button