aspose file tools*
The moose likes JSP and the fly likes Displaying dynamic content on page that resubmits to itself Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying dynamic content on page that resubmits to itself" Watch "Displaying dynamic content on page that resubmits to itself" New topic
Author

Displaying dynamic content on page that resubmits to itself

igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Hello , I have a jsp page and after clicking a specific button, the page resubmits to itself. ie , normally the page is :
http://localhost:8080/switch/switch2.jsp

but after clicking on the url, the page is of the sort,
http://localhost:8080/switch/switch2.jsp?type=pay

when the value of the parameter type = pay, certain lines of code are run in a loop. There is a string called currentMessage whose value changes each time I go through the loop. I would like to print this data on the page (switch2.jsp), but the value of currentMessage only comes up after the entire loop has been run and displays the last value of currentMessage. How do I correct this and make the page switch2.jsp display the current value of the String each time the loop completes a cycle. Thanks.
Satish SN
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
for solving ur problem u need to move the loop logic into a javascript function and call the js function in the body some where and it is upto u how u want the message to be displayed like as the alert or in a place in the jsp page.


Satish SN<br />SCJP 1.4 & SCWCD 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

kumar satish, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

Igwe, please show the code of your JSP that you are having trouble with. Be sure to use the UBB code tags to preserve the formatting.

And no, you do not need Javascript to accomplish this.
igwe kalu kalu ogba
Ranch Hand

Joined: Feb 03, 2005
Posts: 133
Okay, it looks like this:

<%-- Copyright 2005 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: http://developer.sun.com/berkeley_license.html
$Id: index.jsp,v 1.1 2005/04/13 22:34:04 gmurray71 Exp $ --%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import = "javax.xml.stream.*,java.io.*,java.net.*,java.sql.*,java.util.*,java.nio.channels.*,java.nio.*,java.lang.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>

<title>Interswitch.jsp</title>
</head>
<body bgcolor="#ffffff">
<%
//currentMessage is declared here.
String currentMessage = "";
String type = request.getParameter("type");
int totalSuccessCounter = 0;


if(type != null && type.trim().equals("pay")) {


for (int i = 0; i < 5; i++) {
/*

All that happens here is that the jsp page reads a value from a database and does some computations on it. normally takes about 5 seconds in total for this to complete.

*/
totalSuccessCounter ++;
currentMessage = "Transaction " + totalSuccessCounter + " completed";

}//end for loop

totalSuccessCounter = 0;

}//end if

%>

<form method="POST" action="switch2.jsp?type=pay" >
<input type="submit" value ="Final Validation" />
<br/><br/>
<!-- The data is supposed to display here -->
<%=currentMessage%>
</form>
</body>
</html>


All I want is to display the current value of currentMessage as it runs through each loop.

[ July 07, 2005: Message edited by: igwe kalu kalu ogba ]
[ July 07, 2005: Message edited by: igwe kalu kalu ogba ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61064
    
  66

igwe, when posting code it's important to use the UBB code tags as I advised. That's what the little button on the reply page labeled "CODE" is for.

Many people, myself included, will not read unformatted code. It's just too difficult.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
There are two ways to do this as far as I can tell

1. After each loop, flush some javascript to the output that would change the contents of the HTML element that displays the message. Note that at any given time, the user will see only the output that has already been flushed, so any HTML elements that are outputted after the loop will not be seen during the loop.

2. Use AJAX/XMLHttpRequest (or even iframes) to submit the form and constantly poll the server for results until the loop is finished. I think there are examples online about how to do a "file upload progress bar" with AJAX, and a similar principle can be adapted for your needs.

-Yuriy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying dynamic content on page that resubmits to itself