📄 fishnewaction.java
字号:
package org.springframework.samples.jpetstore.web.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.beans.support.PagedListHolder;
import org.springframework.samples.jpetstore.domain.Fish;
/**
* 怴婯夋柺偺傾僋僔儑儞
*
* @author 焨寷曮
*/
public class FishNewAction extends BaseAction {
/**
* 弶婜壔張棟
*
* @param mapping
* 傾僋僔儑儞偺攝抲忣曬
* @param form
* Servlet忣曬
* @param request
* HTTP儕僋僄僗僩
* @param response
* HTTP儗僗億儞僗
* @throws Exception
* 堎忢張棟
* @return ActionForward 揮憲偟偨儁乕僕偺儘僕僢僋柤徧
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// FormBean偺弶婜壔
FishForm fishForm = (FishForm) form;
// Fish偺弶婜壔
Fish fish = new Fish();
// categoryId傪庢摼偡傞
String categoryId = request.getParameter("categoryId");
// 乽怴婯乿儃僞儞傪墴壓偡傞応崌丄categoryId偺抣偑偁傞
if (categoryId == null) {
categoryId = (String) request.getSession().getAttribute(
"categoryId");
}
// 弶婜張棟偺敾掕
if (!"fishNewId".equals(categoryId) && categoryId != null) {
// FORMBEAN偺抣傪僙僢僩偡傞
fish = fishForm.getFish();
// ProductId偑嬻敀偺応崌
if (fish.getProductId() == null || "".equals(fish.getProductId())) {
// 僄儔乕儊僙僢僕
request.setAttribute("message", "Please take Product ID!");
// 僄儔乕夋柺傊挼傇
return mapping.findForward("error");
}
// 慡晹偱嬻敀偑側偄応崌
else {
// FISH偺抣傪僙僢僩偡傞
fish.setCategory(Fish.CATEGORY_ID);
// SQL暥傪峴偆
getPetStore().insertFish(fish);
// 堦棗偺僨乕僞傪庢摼偡傞
PagedListHolder productList = new PagedListHolder(getPetStore()
.getFish(Fish.CATEGORY_ID));
// 昞帵僨乕僞審悢傪僙僢僩偡傞
productList.setPageSize(4);
// request偵僨乕僞傪僙僢僩偡傞
request.getSession()
.setAttribute("searchFishList", productList);
request.setAttribute("productList", productList);
// categoryId抣傪僙僢僩偡傞
categoryId = "fishBrowse";
request.getSession().setAttribute("categoryId", categoryId);
// 堦棗夋柺傊挼傇
return mapping.findForward("browse");
}
} else {
// FORM偺僋儕傾張棟
fishForm.setFish(fish);
// 弶婜抣偺曄峏
categoryId = "firstFish";
request.getSession().setAttribute("categoryId", categoryId);
}
// 怴婯夋柺傊挼傇
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -