• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Link to a JSP on click of a button

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a question about that Javascript? Then let's move it to the forum which is about Javascript.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic