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
JavaRanch » Java Forums » Java » JSP
Bookmark "button link to jsp file" Watch "button link to jsp file" New topic

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


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

Joined: Jan 10, 2002
Posts: 63852

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] [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

Joined: Oct 14, 2005
Posts: 19973

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: 171

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, Liferay Certified Developer 6.1
I agree. Here's the link:
subject: button link to jsp file
It's not a secret anymore!