我有一个.jsp页,正在其中添加字段数据库。我写了一些servlet。当我单击添加按钮时,servlet正在运行,但是没有发送我的.jsp页面。我想发送相同的.jsp页面。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String username=request.getParameter("addUsername");
String password=request.getParameter("addPassword");
String page="";
String url="http://localhost:8983/solr/adminCore";
SolrClient solr=new HttpSolrClient.Builder(url).build();
((HttpSolrClient) solr).setParser(new XMLResponseParser());
SolrInputDocument doc=new SolrInputDocument();
doc.addField("id", UUID.randomUUID().toString());
doc.addField("userName", username);
doc.addField("password", password);
try {
solr.add(doc);
UpdateResponse updateResponse=solr.commit();
PrintWriter out=response.getWriter();
response.setContentType("text/html");
out.println("<script type=\"text/javascript\">");
out.println("alert('Adding an administration account is successful!');");
out.println("</script>");
out.close();
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
page="upload.jsp";
}
request.getRequestDispatcher("upload.jsp").forward(request, response);
//doGet(request, response);
}
}
这是我的servlet代码。它给了我这个错误
Cannot call forward after the response has been committed