我有一个HTML表单
<form method="post" accept-charset="UTF-8"
action="<%=blobstoreService.createUploadUrl("/nonameyet")%>"
enctype="multipart/form-data">
<tr>
<td><input type="text" name=name /></td>
<td><input type="text" name=price /></td>
<td><input type="text" name=quantity /></td>
<td><input type="file" name="image" /></td>
<td><input type="submit" value="add" /></td>
</tr>
发送数据后,我在此处收到:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("image");
if (blobKeys.get(0) == null) {
resp.sendRedirect("/");
}
req.setCharacterEncoding("UTF-8");
BlobKey blobKey = blobKeys.get(0);
Product product = new Product();
String name = req.getParameter("name");
String priceAsString = req.getParameter("price");
int price = Integer.parseInt(priceAsString);
String quantityAsString = req.getParameter("quantity");
int quantity = Integer.parseInt(quantityAsString);
product.setName(name);
product.setPrice(price);
product.setQuantity(quantity);
String url = ImagesServiceFactory.getImagesService().getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));
product.setImage(url);
ofy().save().entities(product).now();
resp.sendRedirect("/index.jsp");
}
现在JSP是:
<%
List<Product> list = ofy().load().type(Product.class).limit(20)
.list();
for (Product product : list) {
%>
<tr>
<td><%=product.getName()%></td>
<td><%=product.getPrice()%></td>
<td><%=product.getQuantity()%></td>
<td><img alt="<%=product.getName()%>"
src="<%=product.getImage()%>" width="100" height="100" /></td>
<td><a
href="/delete-product?id=<%=product.getId().toString()%>">delete</a>
</tr>
<%
}
%>
但是当我在Chrome中查看该页面时,它看起来像这样:
在检查http://localhost:8888/_ah/admin/datastore中的数据后,我可以看到希伯来语中的单词是正确的: 所以我得出的结论是,在从数据存储区到jsp的路上,文本会出现乱码。有人可以帮忙吗?