Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to ask the servlet to stay in the previous jsp page

 
Sean Zhang
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I have a jsp page called a.jsp, and after I click the button "Display," I put an ajax into use so that a second jsp page, b.jsp, is shown inside a.jsp. (So far so good. I make it without any problem.)

Now when I go ahead to make an query (which will be processed by a servlet called the QueryServlet) in b.jsp, if I enter some information which cannot pass the validation, I want to stay in the current a.jsp with the information from b.jsp displayed. I code the following in QueryServlet:



But this will only display the naked a.jsp, losing the information from b.jsp.

Now if I code the following in QueryServlet:



This time, it will only display the naked b.jsp, losing the information from a.jsp.

Can you tell me how to code inside the servlet so that I can stay in the previous jsp page, which has another jsp page displayed inside it (via ajax)? Thank you for your time and help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a complete mess. Please back off a step or two and tell us what you are actually trying to accomplish, rather than how you are trying to accomplish it.
 
Sean Zhang
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I have written very clearly. But I will say it one more time.

By using ajax, a jsp page (named a.jsp) can display another jsp page (named b.jsp) inside it. Now when clicking a button inside b.jsp, if there is some error, I ask the servlet to let me stay in the current page, which is a.jsp including the b.jsp inside it. Do you know how to do it?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean Zhang wrote:I think I have written very clearly. But I will say it one more time.


Advice: being snippy with someone who is trying to help you is not a winning choice.

Of course the whole page will be replaced if you submit. If you don't want that, use Ajax to make the request without a page submit.
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you making this "ajax" call, and what do you do with the response?

A lot of Ajax calls are made just using the XmlHttpRequest object which doesn't replace the code in the browser, but just sends you the text of the response back.

That response doesn't even have to be an html page - it is just text. JSON has become a very popular option as it is easily turned into javascript variables to manipulate.

So to me it sounds like what you want is your call to save the form from b.jsp should be an ajax call that accepts back a success/failure response in json, that you just read into a javascript variable.
Your page thus remains unchanged - still a.jsp with b.jsp embedded in it.
You could then modify the page with javascript as necessary based on the response from the call to "save"

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic