Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Link to a JSP on click of a button

 
Ria Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sharon Melissa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic