在本地一切正常,但是在部署时,当我从 servletConcurrentModificationException
使用时会被抛出。session.setAttribute()
在使用 HTML 表单添加实体后,我使用它从数据存储区返回一个值。
我该怎么办?
这是损坏的 servlet:
public class AdminServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Boolean logged = false;
HttpSession session = req.getSession(true);
Enumeration<String> names = session.getAttributeNames();
while(names.hasMoreElements()) {
String name = (String) names.nextElement();
if(name.equals("logged")) {
logged = (Boolean) session.getAttribute("logged");
}
}
if(logged) {
String p1 = req.getParameter("name");
String p2 = req.getParameter("value");
if(p1 != "" && p2 != "") {
Entity e= new Entity("MyEntity");
e.setProperty("name", p1);
e.setProperty("value", p2);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Transaction txn = datastore.beginTransaction();
Key k = datastore.put(e);
txn.commit();
if(txn.isActive())
txn.rollback();
session.setAttribute("returnedKey", KeyFactory.keyToString(k)); // CRASHES HERE
}
}
resp.sendRedirect("adminpage.jsp");
}
}
谢谢!