Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes button link to jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "button link to jsp file" Watch "button link to jsp file" New topic
Author

button link to jsp file

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

hi ranchers ,

i have a main.jsp file. i want the user to get transferd to the register.jsp , if user clicks a button (register).

i have created a button in main.jsp

main.jsp




how can i link this button to register.jsp file so that user can fill up its registration detail.




Cole Terry
Ranch Hand

Joined: Nov 23, 2011
Posts: 45
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

Cole Terry wrote:


Almost. Omit the silly "javascript:" prefix. It's not necessary and may fail in some browsers.

And, you should use a server-relative path for the JSP URL rather than a page-relative one. It'll be less fragile.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384


after adding "<button type="button" onclick="javascript:window.location=register.jsp">register</button>" in main.jsp user is not transferred to register.jsp

here is whole code of main.jsp




i have placed the main.jsp and register.jsp in WebContent (Eclipse IDE).

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18878
    
    8

Well, that was predictable. What's the URL for your JSP? Don't guess, find out by typing it into your browser's address field.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384




I have declared the main.jsp in Deployment Descriptor under <welcome> tags because it is the homepage of the application. From there on other jsp page is send as a response depending upon whether user is already a member or a new user(register.jsp).

the url to access main.jsp is : http://localhost:8080/DemoProject_j2ee/
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Then your relative path would be window.location=/register.jsp since application name is not necessary for relative path.


No pain, No gain.
OCJP 1.6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: button link to jsp file