• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp&Sevlet problem  RSS feed

 
kavan desai
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchars,
pl help me in finding solution of this problem.i have made one jsp page which insert record into databse.i m following model architecture.The data is posted from jsp page to servlert which insert the record.after complition the request is forwarded to same page.

Now when i m refreshing the page the same request is processed again.so the same values r inserted again.i want stop this .one limitation is that i can not use sendRedirect() method bcoz i want one attribute from that request object in jsp page.

PL Help me thanx in advance...
 
Amin Mohammed-Coleman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code where you perform the database insert, do some checking to make sure that records already exists. if it does then ignore the request...
e.g.

If (!recordName exist)
{
perform insert
}
else
{
//do nothing
}

I have encountered the same problem and approached it this way. The other alternative is to use the Struts framework and implement the Token pattern. See The Struts Framework by Sue Spielman
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you are not using forms/form button to submit the request to servlet. Otherwise, it shouldn't have happened.

Where is your jsp code?
[ August 08, 2005: Message edited by: Adeel Ansari ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amin Mohammed-Coleman:
In the code where you perform the database insert, do some checking to make sure that records already exists. if it does then ignore the request...
e.g.

If (!recordName exist)
{
perform insert
}
else
{
//do nothing
}


Amin, your solution is really good. There must be some check for duplicate entries. We can define a primary key for that, and yes we can also check the duplication first if needed, as you stated above.

But here I think the original poster doesn't even want to process the request on page refresh. This is what I understand.
[ August 08, 2005: Message edited by: Adeel Ansari ]
 
kavan desai
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Adeel i don't know where should i insert the code.so i m inserting the code snippet in your blog here pl check it out.

<form name="futureorder" action="/papertrading/servlet/com.papertrading.MainUserServlet" method="post" onsubmit="return validateForm();">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
.
.
.
<td><input type="image"
src="/papertrading/images/SUBMIT_ORDER.gif" id="cmd_submit" name="cmd_submit" border="0" style="border:0" tabindex="10"></td>

well i also try it by changing it with simple form button but my problem remains problem???
[ August 08, 2005: Message edited by: kavan desai ]
[ August 08, 2005: Message edited by: kavan desai ]
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one limitation is that i can not use sendRedirect() method bcoz i want one attribute from that request object in jsp page.

There is always the option of using sendRedirect() with a new parameter that the jsp page can use to access the attribute (from the session for example).

-Yuriy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!