File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes database update error with success message in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "database update error with success message in jsp" Watch "database update error with success message in jsp" New topic
Author

database update error with success message in jsp

Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
i have a jsp page which displays the database data from a servlet.
After making changes in the jsp page, i am updating the database through servlet.
if the update is successful, i am including a success message in the jsp page.
there is no problem in this process.
Now with the success message in the jsp page, if i try to update again,
the old values are getting updated.
The changed values in the jsp page are not getting updated.
if i refresh/reload the page, values are getting updated.

Kindly suggest me why i am unable to update with that message..

here is the schema of the servlet and jsp page.

<code>

servlet:
--------

public class SubscriptionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// Codes by which i am getting the database values from the model and dispatching to jsp

dispatcher = request.getRequestDispatcher(/jsplink);
dispatcher.forward(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// Codes by which i am updating the database by getting values from jsp

if(data updated) {
String message = "Data Updated Successfully";
request.setAttribute("message ", message);
else{
String message = "No changes made. Please make changes to update the data";
request.setAttribute("message ", message );
}

// here am writing the same code which i had written for doget in order to display the updated values in jsp.

dispatcher = request.getRequestDispatcher(/jsplink);
dispatcher.forward(request, response);
}
}
=================================================================================================
jsp:
----
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<body>
<%
String message= null;
if(request.getAttribute("message") != null){
success= (String)request.getAttribute("message");
%>
<jsp:include page="message.jsp">
<jsp:param value="<%=message%>" name="message"/>
</jsp:include>
<%
}
%>
<!-- Through message.jsp, i am displaying only he message -->
<!-- here i am displaying the database data-->

</body>
</html>

</code>

please suggest me some solution to make this work. thanks in advance.
suchit pandya
Ranch Hand

Joined: Oct 27, 2009
Posts: 43
First of all use code tags when you write a code tag in square [] brackets not in angular <>. dont write it as simple text.

and you haven't displayed the code how you are displaying database values on JSP. It might be like when page load first time you are setting values in hidden variables or session or somewhere else and second time it is taking values from that location.
Abhishek Mhptr
Ranch Hand

Joined: Aug 09, 2009
Posts: 33
thanks for the reply.
from next time i will use code with in [] brackets.

sorry for the delay..
i found out the issue.
i was getting clone values from doGet() and i was comparing with the changed values in doPost() for updating in database.
As there were no changes in doget() values untill we refresh, i was unable to update..

thanks again for the reply..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database update error with success message in jsp
 
Similar Threads
weird functioning of servlet
Need help with a servlet problem
Jsp page is not displaying anything
problem calling servlet to build a list of data from a database and display a jsp page
JSP Not Reading Arraylist