File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Clear a message on page load Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Clear a message on page load" Watch "Clear a message on page load" New topic

Clear a message on page load

Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
I am creating a confirmation message when a form is being submitted successfully. Now when I refreash the page that confirmation message does not go away. Is there any way I can remove that message when the page refresh. Thanks!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

How can we say anything without knowing what's putting it there in the first place?

[Asking smart questions] [About Bear] [Books by Bear]
Sam Saha
Ranch Hand

Joined: Jan 23, 2010
Posts: 104
Here I am doing a form submission from a JSP. When the form submits I am calling a servlet from the form and in that servlet I am setting a attribute using setAttribute() for that message. Using request
.getRequestDispatcher I am coming to the JSP again. Now using getAttribute() I am populating that message. Now when I refresh the page I want this message removed.

This is the code for the Form:

<form name="feedbackForm" action="feedback" method="post">
<input type="hidden" id ="uRecid" name="userRecID" value="<%= request.getSession().getAttribute("USERRECID") %>" />
<input type="hidden" id ="appType" name="applicationType" value="AME" />
<input type="hidden" id ="fromFForm" name="fromFeedbackForm" value="Y" />
<div id="messageText">
<textarea id="feedbackText" name="message" rows="5" cols="70" class="dim" onkeypress="return imposeMaxLength(this, 3999);" onclick="javascript:changeClass(this.className,;">The more specific your question or comment, the better service we can provide.</textarea>
<div id="message"></div>
<ul class="buttons">
<li class="secondary">
<input type="submit" value="Submit Feedback" />
<% if(request.getAttribute("confMessage") != null){
System.out.println("The value of confmessage is: " + request.getAttribute("confMessage")); %>
<td><%= request.getAttribute("confMessage") %></td>
<% } %>

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Hi Sam,
Why are you not using any client side scripting language like javascript for this purpose?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Why would scripting be appropriate?
Sean Clark

Joined: Jul 15, 2009
Posts: 377


If it is at request scope that means that you are setting it on every request and when you press refresh it is another request.
You will need to have some logic in your servlet that sets it only when it is appropriate.


I love this place!
I agree. Here's the link:
subject: Clear a message on page load
It's not a secret anymore!