I'm basically giving output to my datas from database from Data shown servlet and when pressed update datas I'll update with the given contenteditable <h2>
then go into new servlet take the value update in MongoDb and redirect to data shown servlet. Thing is I cannot take the <h2>
from a responed servlet. Questions are how can I take the contenteditable <h2>
value from other servlet and how can I redirect to this servlet again?
Data shown servlet:
PrintWriter writer = response.getWriter();
// build HTML code
String htmlRespone = "<html>";
htmlRespone +="<head>";
htmlRespone += "<form method=\"post\" action=\"updateServlet\">";
htmlRespone += "<h2 id=\"id\">Id: " + combobox + "</h2>";
htmlRespone += "<h2 >Status:</h2>";
htmlRespone += "<h2 id=\"stat\" contenteditable='true'>"+array[0]+"</h2>";
htmlRespone +="</head>";
htmlRespone += "</html>";
// return response
writer.println(htmlRespone);
Data update servlet(status returns null now.):
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// code to process the form...
status=request.getHeader("stat");
PrintWriter writer = response.getWriter();
// build HTML code
String htmlRespone = "<html>";
htmlRespone += "<h2>" + status+ "</h2>";
htmlRespone += "</html>";
// return response
writer.println(htmlRespone);
}
If you need to include the response generated by another servlet, call request.getRequestDispatcher("path to include").include()
.
If you need to pass the request to another thread, use request.getRequestDispatcher("path to forward").forward()
.
If you need to pass a value to the servlet you're including or forwarding, use a request attribute.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.