• Post Reply Bookmark Topic Watch Topic
  • New Topic

Refresh problem in Servlets !!  RSS feed

 
Nabha Panat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a strange problem with servlets:
Let me first describe the requirement.
I have a servlet which throws an HTML page. The HTML form contains a table and a button. On clicking the button, I need to add a new row to the table.
Now the problem is:
For the first time when I click on the button, a row gets added properly. But if I refresh the browser, again a row gets added.
This happens everytime I refresh the browser.
Has anyone faced this kind of a problem? In case if u know the solution please share it...
thanks in advance !!!
regards,
Dhanashree
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After performing an operation like this (usually after a POST) I tend to use reponse.sendRedirect("new page"); since this will change the details in the clients browser.
If they hit the reload, they reload the "new page" rather than resubmitting the data that inserted the row.
Dave.
 
Nabha Panat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do u exactly mean by "new page"??
Should I specify the name of the servlet there ??
 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont you try by including the destroy method in the servlet..it will cause the servlet engine to reload the servlet class file again when refreshed
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
destroying the servlet won't help, yes you put the URL of a new page in there...

Dave.
 
Nabha Panat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using response.sendRedirect("d:/RAndD/AddNewRowServlet") but I am getting the following exception:
java.io.IOException: tried to write more than content length
at sun.servlet.http.HttpOutputStream.check(HttpOutputStream.java:282)
at sun.servlet.http.HttpOutputStream.write(HttpOutputStream.java:318)
at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:207)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:221)
at java.io.OutputStreamWriter.close(OutputStreamWriter.java:235)
at java.io.BufferedWriter.close(BufferedWriter.java:234)
at java.io.PrintWriter.close(PrintWriter.java:130)
at AddNewRowServlet.doGet(AddNewRowServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at sun.servlet.http.HttpServerHandler.sendResponse(HttpServerHandler.jav
a:165)
at sun.servlet.http.HttpServerHandler.handleConnection(HttpServerHandler
.java:121)
at sun.servlet.http.HttpServerHandler.run(HttpServerHandler.java:90)
at java.lang.Thread.run(Thread.java:466)
Please let me know what's going wrong !!
I tried using the destroy method also.. but it didn't work.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be redirecting to a servlet, why do you have a file path there?
eg
response.sendRedirect("http://www.yahoo.com"); //will work
response.sendRedirect("/AddNewRowServlet"); //will work if this is where the servlet is...
 
Nabha Panat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet is running through the servletrunner on my machine.
That was the reason why I gave that path.
I also tried the following path: http://127.0.0.1:8080/servlet/AddNewRowServlet
(i.e the URL which appears in the browser for the first time)
but nothing is working !!!
----
I tried with the folwoing URL http://127.0.0.1:7001/servlet/AddNewRowServlet
This time it gave me differnt exception for the methid sendRedirect() ... "response already committed" . It do not exxcute the method. Still not got the solution...


[This message has been edited by Nabha Panat (edited September 12, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!