私はhttpsessionに少し問題があり、それを修正する方法はわかりません。ここに問題があります。
私はset<Product>
のクラス人を持っており、そのクラス人を に設定しました。このようにrequest.getSession。
文字列email = getRequest()。getParameter( "email"); String credential = getRequest()。getParameter( "credential");その後
validEmail(email);
validCredential(credential);
if(existError()){
setValues(email, credential);;
forward(login);
return;
}
PersonService ps = serviceFactory.getService(PersonService.class);
boolean success = ps.validatePasswordAndEmail(email, credential);
if(success){
Person person = ps.getPersonByEmail(email);
getSession().setAttribute("person", person); here you can see the object person into the session
forward("/packed.jsp");
}else{
addError("Email or Credential is not valid!");
setValues(email, credential);
forward(login);
return;
}
ユーザーが別の ファイルに来る彼らの正しい情報を置けばpacked.jspと呼ばれ、それらが記録されます。
私の問題は、システムにログインしている製品の人物を編集するときです。私はここに私のコードを表示してみましょう
packed.jspというページは、クリック をログに記録している人は、その後、彼はすることができますように
public class EditProductAction extends Action {
private String editProduct = "/edit_product.jsp";
private String packed = "/packed.jsp";
@Override
public void process() throws Exception {
Integer id = Integer.parseInt(getRequest().getParameter("id"));
String brand = getRequest().getParameter("brand");
String model = getRequest().getParameter("model");
String name = getRequest().getParameter("name");
String quantity = getRequest().getParameter("quantity");
String color = getRequest().getParameter("color");
String info = getRequest().getParameter("info");
ProductService ps = serviceFactory.getService(ProductService.class);
Product product = ps.getProductByID(id);
if(name == null){
getRequest().setAttribute("product",product);
forward(editProduct);
return;
}
product.setBrand(brand);
product.setModel(model);
product.setName(name);
product.setQuantity(Integer.parseInt(quantity));
product.setColor(color);
product.setInfo(info);
ps.update(product);
getResponse().sendRedirect(getRequest().getContextPath()+packed);
}
}
の下に、このサーブレットに来る湖底を持っていますすべてがうまくいくのを見てみましょう。しかし、私がpacked.jspのページに戻ったときには、 はmodyfiedという製品を表示していませんが、データベースにはうまくいきます。ここ
<div class="mainDiv">
<table border="1px" width="80%">
<tr>
<th>BRAND</th>
<th>MODEL</th>
<th>NAME</th>
<th>QUANTITY</th>
<th>COLOR</th>
<th>INFO</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>
<c:choose>
<c:when test="${empty person.products}">
<tr>
<td colspan="8" align="center"><span>You don't have any product yet!</span></td>
</tr>
</c:when>
<c:otherwise>
<c:forEach var="p" items="${person.products}">
<c:url var="urlDel" value="servlet">
<c:param name="id" value="${p.id}" />
</c:url>
<c:url var="urlEdit" value="EditProduct.action">
<c:param name="id" value="${p.id}" />
</c:url>
<tr>
<td>${p.brand}</td>
<td>${p.model}</td>
<td>${p.name}</td>
<td>${p.quantity}</td>
<td>${p.color}</td>
<td>${p.info}</td>
<td><a href="${urlEdit}"><img src="<%=request.getContextPath()%>/images/edit.png"></a></td>
<td><a href="${urlDel}"><img src="<%=request.getContextPath()%>/images/delete.png"></a></td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
packed.jsp私は戻って、私は製品がmodyfied見たいpacked.jspするときに、製品を変更したいと思います。大変ありがとうございます。