Change html/jsp contents dynamically without restart the server - java

Am developing a application in which html content of the pages are able to change dynamically. From my application itself user can able to change their html pages using drag and drop form(which is used to design pages).
Once the page is edited and saved successfully, I need to restart the server to reflect the changes in browser which is hurting lot.
I want to build this solution without restart the server.
What I found:
Number 1: I try to have my html pages in DB or file and in run time, i will read from that and render in browser.
Problems:
1: performance
2: HTML code is working fine in out.print() But JSP code are showing as code itself in browser.
Is there any other solution available for to fix this or any existing framework available?

Related

Saving a information displayed as different tab in browser to .html file

I am working on a project which is developed with Java Struts 2 framework. I am completely new to this. In project, when user clicks on a report button, a report is shown in different tab (the url of it looks like https://localhost:8181/myApplication/businessReport.do).
Goal: What I want is saving this report as html file in backend somehow. It is perfectly OK when user sees the report as he is seeing currently. It just needs to be saved in backend somewhere. The reason to do this is, te application is going to shutdown soon and our client wants to save those reports somewhere for future reference.
I could find businessReportForm.java, businessReportAction.java and also businessReport.jsp files in my project. I assume they should be of my interest.
Note: It uses mapping.findForward from Action mapping
I do not understand following and it would be nice if someone can help with that.
What could be the last point in (with respect to strut framework) where all the information for report would be ready ? (I would lke to use it to create .html file out of it)
What I need to change here in order to achieve the goal ? changing .jsp , changing Action or should change be done in corresponding Action class ?
in the url what does businessProcess.do actually mean with respect to jsp and servlet ?
any other idea what should be the approach to do what I want to do ? (saving report as html in background)

How to render .jsp from database without .jsp physical file

I am developing an application where I will have only loader.jsp which will load all other jsp files from the database. Like I am having all the coding for jsp file in database so that i can able to change the html content without restart the server in database itself.
Is there any framework already existing to implement this and what is the best way to achieve this?
If yes for render .jsp file dynamically, how to render css and js dependency also dynamically?
So my exact requirement is, I will have only loader.jsp which will load all other pages stored in database based on the path param.
http://localhost:8081/myApplication?page=mypage
TECHNOLOGIES USING: java spring boot
NOTE 1: I am not gonna render based of conditions or some parts of the file, I need to render entire page as it is from the database columns.
NOTE 2: if loading .jsp is not possible since jsp code need to be compiled, then can i load .html file? ex: loader.jsp will load a.html, b.html, c.html from database
NOTE 3: Am building application where user can able to drag and drop UI elements to create webpages and once if they save, their changes need to reflect on run time without restart. like they have one page in their own application itself to change their UI elements.

Dialog box in Spring MVC controller

Is there a way to display a (preferably modal) dialog box in an servlet controller ? If it isn't modal that is something I can deal with (!?) as long as it initially appears above the browser.
Essentially I have a form with a table and 2 buttons on it. One button takes the user to a different place in the workflow and is irrelevant to this question (just to explain why the other one doesn't 'go anywhere').
The other button currently goes back to an MVC controller, calls some code to export the table to excel and then reloads the web page. This is all working okay except the way I am calling the dialog box is calling it underneath the browser. I suspect this is because I am sending null as the frame but I'm not sure what to put in its place ?
JOptionPane.showMessageDialog(null, "Export Completed.", "Excel Export", JOptionPane.INFORMATION_MESSAGE);
Many thanks.
I am not too sure what you are trying to achieve from your question and without any code examples. However, presumably what you are doing (guessing here), is that you are trying to export some data from some data source and convert it to an Excel file. You have to keep 3 things in mind.
Web applications work via HTTP requests and responses. So the only thing a Servlet can do is send back an HTTP response that indicates that the export was successful. Whether you use a traditional page, or maybe use AJAX to avoid refreshing the page is purely your design choice. You could also start with a simple page and then change to AJAX combined with JQuery later once you get used to what is happening.
Exporting the excel sheet to the server does not mean that your client has access to it. Speculating here, but you will probably need a mechanism for your user to get the file. One simple approach used by many webapps is to actually send the Excel file as the Servlet response itself. So what would happen is that when the export is completed the browser starts receiving the file and the user sees it downloading. From your servlet you will just need to set the right mime-type and set the content-disposition header to state that the file is an attachment (so that the browser downloads it as a file).
httpresp.setContentType("text/csv");
httpresp.setHeader("Content-disposition", "attachment; filename=\"export.csv\"");
You will probably also need to set the file size. There are various full examples on SO if you look for further details.
When performing these operations remember that users can interrupt the browser or refresh. If the user presses F5 he might cause your application to do the export again. One common approach to this is called 'redirect-after-post'. Basically you redirect the user to a page which just displays the outcome, without performing the operation again. This way if he presses refresh, he is just refreshing the page with the message.

Download HTML of a webpage that is changed by JavaScript

The program I am writing is in Java.
I am writing a little program that will download the html of webpages and save them. It works easily for basic pages that don't use JavaScript. But how can I download the page if I want it after a script has updated it? The page I am dealing with is actually updated by Ajax which might be one step harder.
I understand that this is probably a difficult problem that involves setting up a JavaScript run time environment of some kind. I am prepared for a solution of any level of difficulty, I just don't know exactly how to approach it or where to get started.
You can't do that alone with Java only. As the page that you want to download is rendered with javascript, then you must be able to execute the javascript to get the whole rendered page.
Because of this situation, you need to use a headless browser which is a web browser that can access to web pages but can’t show the output within a GUI, aims to provide the content of web pages as fully rendered to serve to the programs or scripts.
You can start with the most famous ones which are Selenium, HtmlUnit and PhantomJS

Opening a Webpage at an Anchor in a Browser through Java

I have created an application in JSwing that has a button that I want to open the user manual (which is a html file) in a browser. I can successfully open the entire webpage, but I want to link to certain anchors in the document. For example I am trying to use this code:
URI uri = new URI("c:/Giggafriggin/user_manual/user_manual.html#h1_3");
Desktop.getDesktop().browse(uri);
But this causes an error, claiming the file cannot be found. But if leave off "#h1_3" it opens the page in a browser without a problem. The anchors work when i enter them into the browser manually. Any ideas?
You -could- have that linking to another html page which goes to the end uri. Unfortunately, Java is not a web browser.
Looks like this is a known issue you wouldn't run into if you were using HTTP instead of a local file.
One easy fix is simply to point to a version of the that's already online instead of on disk.
If you can't assume the content is available online, you could always spin up an embedded HTTP server like jetty inside your application and point to that instead.

Categories

Resources