• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call a jsp page query

 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have two jsp pages. The first one with "Hello World" text message. The second JSP page with "Hello JSP" text message. Now in my third JSP page I have two buttons button1 and button 2. Can someone suggest some code snippet which I can use to call the first JSP page on click of the button 1 and on click of button 2 , it should call the second JSP page?

On click of the first button only the first jsp page value should be displayed and on click of the second button only second page value should be displayed.

Kindly suggest the approach to achieve this.

Kind regards
Deb
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the simplest way would be to put each button in its own form, and have the action of the form request the appropriate JSP.
 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I think the simplest way would be to put each button in its own form, and have the action of the form request the appropriate JSP.


Hi Paul,

I did something like this in the below code snippet but it didn't work. On click of the link, the respective jsp files should be only called and executed but it doesn't work? Not sure why?

I did it using link for Hello-world instead of buttons. Can you suggest any changes in the below code or any refernce code snippet that can be useful for my scenario?

 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, I have no idea what all that code has to do with your original question, the one about the two buttons. There aren't any buttons in the code you posted.

I can tell you that when that JSP runs, it will include (and execute) both of the other two JSPs. The result of those JSPs may be hidden but it has already been produced by the time that Javascript is ready to be used.

What's your objection to the ordinary HTML version that I suggested?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Foni kumar wrote:On click of the link, the respective jsp files should be only called and executed but it doesn't work? Not sure why?

Because you have a fundamental misunderstanding of the way that JSP works. You can;t execute any JSP on the click of a link or button. You can load a new page, but any JSP that's on the original page is executed on the server long before the page is sent to the browser where the user can click on things.

You should read this article to understand how JSP operates,

Then, if you need to cause server-side action to execute as the result of a user action (doubtful in this case, as Paul has pointed out), you need to investigate Ajax.
 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm sorry, I have no idea what all that code has to do with your original question, the one about the two buttons. There aren't any buttons in the code you posted.

I can tell you that when that JSP runs, it will include (and execute) both of the other two JSPs. The result of those JSPs may be hidden but it has already been produced by the time that Javascript is ready to be used.

What's your objection to the ordinary HTML version that I suggested?


Ya I think the first one you suggested is a good approach the only query that I had was will it call only a specific parameter or render the entire page on request by the approach you had suggested
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't understand the phrase "call a parameter". And anyway I didn't see anything about parameters in your original post.

And yes, sending a request from an HTML page (which as you should now know, is what a JSP produces) does reload the whole page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!