Display HTML form only once in Tomcat Server - java

I have an tomcat server application where in a HTML form is displayed. Once I submit the data the page redirects to another page. In the back-end there is a JAVA program which takes some hours to complete execution. In the mean time if some-one tries to open my HTML page displaying form(First page) from another browser or another tab, it has to redirect automatically to the execution page. Is it possible to do this with Tomcat Server and JAVA? (I am using it on RHEL machine. So please do not post platform specific solutions.)

Here is an approach:
Introduce a flag in your server side code to determine whether the multi-hour-job is in progress
Whenever backend job is started, set the flag. When job done, reset the flag.
Either in your servlet doXXX method or in a servlet filter, check flag if set then redirect, if not then return the form view

Related

JSF to send request on local machine on live application

We are doing university project in JSF 2.2 with primeface framework. We want to develop the application which is hosted on live server but the request needs to be sent on local machine from which user is accessing application. This might be stupid question but I would like to know if there is any possibility where we can do such implementation.
For example: We will host application 'www.somesite.com' on server, in this application we will have multiple forms, but we want this forms to be submitted to user local machine where we will deploy required component/service which will take the input from user and also send required response to user. It means, the view will be render from host server but data will be bind from local machine.
One way to do this is, when user submit form, we will send the request to host server and from server we will send data to user local machine where we will deploy required component/service which will be listening to server request/response, but we want to eliminate this layer and want to send direct request to user local machine as soon as user submit form
I would appreciate if you can help us....
If I understood well your request you need to change the action of the form to be able to send the request to a localhost.
I think the only way to do so is to use a pure html form and not a h:form. With an html form you can set the action attribute to a localhost.
JSF form with URL action?
But in this case you can have problem to use the jsf component, you will have a jsf warning (with javax.faces.PROJECT_STAGE set to Development)
The form component needs to have a UIForm in its ancestry. Suggestion:
enclose the necessary components within
see here for BalusC explanation

jsp - Update data without refresh the page using jquery and ajax

I am using jsp with script tag (<% %>) .And I use ajax to update some contend of jsp which have Java code with in script. In the script tag I get some session variable to process. And in ajax call I update that session variable from the action class but I can't get updated value for the front end jsp variable(inside the script tag).
Can any one tell me how do I do this?
You are trying to use javascript to update some Java variables which, fortunately or unfortunately, have already been processed by your application server and are no longer present on your output HTML page.
I think you mixed up server side and client side programming. JSP code is executed at server side and a your session data will remain at server only. All the output generated from server will be sent to browser and displayed. Although you make a ajax call, the session data will only update at server side but not update at browser unless your ajax call can handle the result from server and update the content accordingly.

redirect page invoked from java class

Im new to java web app, JavaEE if I'm not mistaken. it happen that I was task to finished a certain project, while learning Java web app. So I'm not even certain if where am at is right. Here is the dilemma Im facing.
It had a timer on a certain java class. based on the timer count, per couple of seconds, the page is suppose to redirect to another page. To explain further of what I want to achieve, refer to the following:
user opens Page1
after 30 mins redirects to Page2
after 15 minutes redirects to Page3
the timer is set on the java class and not on the jsp file.
is there a way that the java class could issue a redirect command to the web browser?
As far as I know this is very tricky if not near impossible to achieve without using the client side. The problem is that the communication between the server and the client works in a request/response manner. This means that if the user requests a page, controller prepares it and then it is served to a client via response. Doing it right away without a timeout isn't a problem with response.sendRedirect(), but in order to push an action from the server to the client after some timeout, you would have to implement some sort of a listener on the client side.
This problem can be of course solved with a script on the client's side which could handle automatic redirects.
Use JavaScript timeout function and not Java's
setTimeout(function(){
// Set your redirection logic here
},(60000 * 10 ));
Try this :
response.sendRedirect(request.getContextPath()+"/YourJsp.jsp");

Loading resources before running java code in servlet

I have a servlet in tomcat. It takes a really long time for the java code in the backend to execute. Is there a way to load static resources (css,images,javascript) in parallel with the code in the backend? Right now, they are only loaded once the code finishes running.
You could use an Ajax-style solution where you paint your page without data, with a placeholder for retrieving the data, maybe even with a "loading" spinner graphic.
The way that an Ajax call works, when the page is loaded, some Javascript will fire that will launch an Ajax request to Tomcat via XmlHttpRequest that will start the calculation. The browser will notify the browser when the tomcat request is completed. Then there will be some javascript in the webpage that will take the response and replace the placeholder. If the server returns an HTML fragment, it's as simple as executing in javascript placeholder-div.innerHtml = your-response-text.
Here's a basic tutorial on Ajax and a Java-based example that has the web front-end communicating with a Java Servlet back-end.

JSF: Wait for party, then redirect

I'm using JSF 2.0 and Glassfish 3.1 and have the following problem:
I've got an application in which two users must participate. The first user should set up the session and then get to a wait page. When the second user joins, the first one should be redirected to the application page. Is this possible in JSF, and if yes, how?
Create an Ajax polling mechanism
Invoke an action from Ajax, check if condition met
If met using JavaScript code redirect the user (Or you can also make it redirect from action)

Categories

Resources