Set value for a html label from a servlet - java

I'm not sure Is this possible ?
but, I have a label in html page.
<label name='example'>Page 1</label>
I want to update the label value to something else after i get to another page from my controller servlet:
<label name='example'>Page 2 (update being update from servlet)</label>
Can anyone understand my question and help?

It is not possible to directly update it as a servlet from Page 2 can only write response to Page 2 .
However you can use session to share/update data between pages , update the session variable in page 2 and auto-refresh the page one every few second to reflect that change.
If you were opening a child window however then you can use the JavaScript on child window to update the items on Parent page.

Related

How to automatically reload a jsp based on other page action

I have a situation that i can't handle and thats why need your help.
I have a jsp page (mention as A in below pic) where there are many rows and each of them can be edited.
At the end of the A jsp page, there is an option to print the page data.
Now, if some body clicks on the edit link/button, another page will open contain the data for that particular row and user can modify the data in the second page(i,e B).
Now, i want, as soon as the user save the B page, A page should be refreshed automatically to provid the updated data for printing.
Please guide me on how to acheive that . I'm using Spring MVC framework for the java application.
The Spring MVC way to meet your requirement is:
the Edit buttons in page A should be links calling page B with the id of the line to edit, something like Edit
the SaveAndClose button in page B should be a submit button that posts the edited values to a controller method. After server side processing, the controller method should redirect to page A. As a side effect, you use the PostRedirectGet pattern which avoids the ugly do you want to send again ... ?"
#RequestMapping(path = "...", method = RequestMethod.POST)
public String saveAndClose(...) {
...
return "redirect:/path/to/pageA";
}
Of course this will display all pages in same window.
If you want to redisplay the window containing pageA on the Save & Close from page B, still allowing the save to be known to the server, you should redirect to a special page (say pageC) that just contains javascript code asking the browser to redisplay pageA. You can either pass the name of the window containing pageA in a hidden field, or you can decide that as the programmer of the web application you know where it should be.
It can be achieved like this. Follow the steps mentioned
1] When you click on edit button in Page A, pass the id of the row to Page B as request parameter.
2]In Page B JSP receive the id of the row and store it in a hidden element.
3]Create a JavaScript function in Page A which should receive row Id and Modified data as parameter. Lets name it this function as updateRows(rowId,modifiedData). In this function write code to update the with id 'rowId' with modified data using javascript
4]Now When you click on 'Save & Close' Button in Page B. Save the data using call to server. If save succeeds then invoke the function updateRows passing it rowId stored in hidden element and modified data as parameters. This function will update the DOM with latest data.
This way you will avoid making server call to refresh the data
There is one more way if you don't want to use ajax.
In Page A define a javascript function refreshPageA(). In this function add page refreshing logic.
When you click on 'Save & Close' button in Page B save the data in server and forward to a plain jsp. In this JSP declare a onload handler. Inside onload handler add following code
opener.refreshPageA();
window.close()
This will refresh pageA and close page B window

How to submit all information from a JSP page including two other pages?

I have a main JSP file that includes other JSP files, I want to submit a request from the main page to include the parameters in all files.
The scenario is that my main page includes two other pages:
a page with search criteria fields and search button
a page with the results table and a save button
When I submit the changes in the results table, my servlet doesn't see the information from the other included JSP page (search criteria). How can I fix this?
My question could also be in another way: is it possible to make to sub JSP pages submit the same form from the parent JSP page?
As already mentioned by t0mppa wrap the two inserts in your main page with the tags. Any fields inside them will be submitted.

Wicket Table css not rendered after ajax update?

I have a datatable with some items. The datatable has some css on the table tag. When I update the dataproviders model list and send the component back with ajax the css doesn't get rendered.
However if I send the entire page using ajax the table is rendered correct.
Example:
<wicket:panel>
<table class="striped">
</table>
</wicket:panel>
This css class gives odd and even a different css.
This is how I update the component after changing the dataprovider.
ajaxRequestTarget.add(MyPage.this.get("myPanel")); //this panel contains the table
The data gets added but the css markup is gone.
Refreshing the page brings back the css.
ajaxRequestTarget.add(MyPage.this); //send the entire page
This works but the entire page gets refreshed(and this make the page scroll up.
Whats the difference in component rendering if you send the entire page, instead of only 1 component/panel?
I'm using chrome.
If you render styles via jQuery, you'll have to call it again to re-paint correctly.
ajaxRequestTarget.appendJavascript("renderMethod('.striped');");

Why i can't use request.getParameter in my form

i have a question about using request.getParameter(), i knew that it can use to post the value using request.getParameter, Is it necessary match request.getParameter and <input>???
My original code in HTML:
<INPUT type=submit name="submit" value="download">
In JSP:
String start = request.getParameter("submit");
Now I want to change a button and use div
div name="submit"id="submit" class="btnStyleFunc"
onclick="document.body.style.cursor='wait';this.disabled='true';
document.getElementById('form').submit();">
But it doesn't work, anyone can help me ?
Now i use the method below, but another problem is raised...the action does not stop...
String start = request.getParameter("submit1");
<input type=hidden name=submit1 value=download>
<div class="btnStyleFunc" onclick="document.body.style.cursor='wait';
this.disabled='true';document.getElementById('form').submit();">
Does anyone know what the problem is ?
A clicked submit button is a successful form control and its name/value pair will be submitted to the server in the form data.
If you submit a form with JavaScript, there is no clicked submit button, so it won't appear in the data. A div cannot have a name and is not a form control anyway — it isn't a submit button, even if it triggers JavaScript that submits the form.
Using a div with JavaScript also breaks the form for:
Anyone not using a mouse/trackpad/etc to navigate the page (a div won't get the focus when tabbing through interactive elements)
Anyone with JavaScript disabled
Anyone using a screen reader in forms mode (div elements are not form controls).
Use a real submit button instead.

Update iframe in container page on submit of <form> in container page

I have a main html page which contains an IFRAME.
I have a server side jsp code that is displayed with some default values inside the IFRAME for the first time.
Whenever a person tries to use a search button in the main page the results are displayed in the IFRAME updating its content.
I have a servlet that does the calculation on the searched data and updates the IFRAME content.
The problem:
I have used the sendRedirect method in servlet to refresh the IFRAME but to no avail.
The string I am passing to sendRedirect is /results.jsp?search=value&size=1 (jsp to be displayed in iframe).
The servlet does its calculation work properly but opens a new page in place of the mainpage: not a desired output.
The mainpage with its interface should remain there, only the IFRAME should refresh.
My question:
Is this the correct method to refresh an iframe? If not kindly tell me what should I use to update my iframe (jsp) via servlet.
PS: Please forgive the absurdity of the quesion if any. I am new to the jsp-servlet.
Any help is much appreciated
When you do a redirect using response.sendRedirect() method, the actual 'frame' where the servlet was called will be modified. That frame can be the entire page, or an iframe, or even the legacy frames used in javadocs.
As #Jake223 said, set the target attribute to the iframe name in the form:
If you are using a form to submit the information, then you do something like this:
<iframe name="resultframe"></iframe>
<form action=[path to servlet] target="resultframe">
<input type="text" name="searchq"/>
<input type="submit" value="search"/>
</form>
If you are using javascript to create the iframe, then use the src attribute of the iframe:
<iframe src=[path to servlet]?[request params]></iframe>
If the search mechanism is an HTML form, you can set the target attribute of the form to the name of the iframe in question. See W3Schools's page on this for more details.

Categories

Resources