PentaKon
PentaKon

Reputation: 4636

Communicating from one jsp to another via servlet

I have 2 jsp pages. A main page and a form page. The main page has a grid (extjs framework) and when I click on a row it opens my form jsp page. What I want to achieve is, once the form is submitted, I want my main page to refresh its grid in order to show the new data that was submitted from the form. Note that the form page is a new window. They both co-exist in different browser windows (the user sees both at the same time).

One way I thought of doing this is via server sent events. After the form submit, I send an ajax request to the servlet from the form.jsp and it was supposed to respond with an event-stream listened by my main.jsp but it doesn't seem to work. When I try to create the EventSource object it gives me the error:

EventSource's response has a MIME type ("text/javascript") that is not "text/event-stream". Aborting the connection.

The error seems to appear in my doctype declaration: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

I'm not really sure why this is happening. Any help on that would be appreciated.

Regardless of the method I tried to implement, is there a better way of doing this? Or a fix for the server sent events method?

Upvotes: 0

Views: 139

Answers (1)

Jafar Ali
Jafar Ali

Reputation: 1114

You can do this window.opener.location.reload(true) on form submission. 'true' if you wand to reload this page completely from the server.

In case you don't want to refresh the whole page then you can follow the below steps.

  • create a method on main page with code to refresh your grid. function refreshGrid().
  • call this method from the opened page using the opener reference. window.opener.refreshGrid().

Hope this help.

Upvotes: 1

Related Questions