packagecom.game.products.web.actions;importjava.util.List;importjavax.servlet.http.HttpSe" />

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

struts+spring+hibernate的web應用 Web層代碼編

系統 1876 0

Web 層代碼量比較大,涉及的地方也比較多,考慮到文章過于龐大,所以分兩篇寫。
我們還是先從主要的
action 開始吧。

com.game.products.web.actions 包中新建 ProductsAction ,這是一個 DispatchAction ,代碼如下:

<o:p></o:p>

?

package ?com.game.products.web.actions;

import ?java.util.List;

import ?javax.servlet.http.HttpServletRequest;
import ?javax.servlet.http.HttpServletResponse;

import ?org.acegisecurity.AccessDeniedException;
import ?org.apache.struts.action.ActionForm;
import ?org.apache.struts.action.ActionForward;
import ?org.apache.struts.action.ActionMapping;
import ?org.apache.struts.actions.DispatchAction;

import ?com.game.commons.Pager;
import ?com.game.commons.PagerService;
import ?com.game.products.model.Products;
import ?com.game.products.services.iface.ProductsService;
import ?com.game.products.web.forms.ProductsForm;


public ? class ?ProductsAction? extends ?DispatchAction? {
????
????
private ?ProductsService?productsService;
????
private ?PagerService?pagerService;
????
????
/**?*/ /** ?
?????*?顯示所有信息
?????
*/

????
public ?ActionForward?doGetProducts(
????????????ActionMapping?mapping,
????????????ActionForm?form,
????????????HttpServletRequest?req,
????????????HttpServletResponse?res)
{
????????String?flag
= req.getParameter( " flag " );
????????
????????
int ?totalRows = productsService.getRows();
????????String?currentPage
= req.getParameter( " currentPage " );
????????String?pagerMethod
= req.getParameter( " pagerMethod " );
????????
????????Pager?pager
= pagerService.getPager(currentPage,?pagerMethod,?totalRows);
????????
????????List?productsList
= productsService.getProducts(pager.getPageSize(),?pager.getStartRow());
????????
????????req.setAttribute(
" productsList " ,?productsList);
????????req.setAttribute(
" PAGER " ,?pager);
????????req.setAttribute(
" flag " ,?flag);
????????req.setAttribute(
" totalRows " ,?String.valueOf(totalRows));
????????
????????
return ?mapping.findForward( " all " );
????}

????
????
/**?*/ /** ?
?????*?顯示一條信息
?????
*/

????
public ?ActionForward?doGetProduct(
????????????ActionMapping?mapping,
????????????ActionForm?form,
????????????HttpServletRequest?req,
????????????HttpServletResponse?res)
{
????????String?flag
= req.getParameter( " flag " );
????????String?gameId
= req.getParameter( " gameId " );
????????String?fieldname
= "" ;
????????String?value
= "" ;
????????
if (flag.equals( " 2 " )) {
????????????fieldname
= (String)req.getParameter( " fieldname " );
????????????value
= (String)req.getParameter( " value " );
????????????req.setAttribute(
" fieldname " ,?fieldname);
????????????req.setAttribute(
" value " ,?value);
????????}

????????
????????Products?pd
= productsService.getProduct(gameId);
????????req.setAttribute(
" pd " ,?pd);
????????req.setAttribute(
" flag " ,?flag);
????????
return ?mapping.findForward( " one " );
????}

????
????
/**?*/ /** ?
?????*?添加信息頁面
?????
*/

????
public ?ActionForward?doAddProductPage(
????????????ActionMapping?mapping,
????????????ActionForm?form,
????????????HttpServletRequest?req,
????????????HttpServletResponse?res)
{
????????String?flag
= req.getParameter( " flag " );
????????req.setAttribute(
" flag " ,?flag);
????????String?fieldname
= "" ;
????????String?value
= "" ;
????????
if (flag.equals( " 2 " )) {
????????????fieldname
= (String)req.getParameter( " fieldname " );
????????????value
= (String)req.getParameter( " value " );
????????????req.setAttribute(
" fieldname " ,?fieldname);
????????????req.setAttribute(
" value " ,?value);
????????}

????????
????????String?maxid
= productsService.getMaxID();
????????req.setAttribute(
" maxid " ,?maxid);
????????
return ?mapping.findForward( " add " );
????}

????
????
/**?*/ /** ?
?????*?添加信息
?????
*/

????
public ?ActionForward?doAddProduct(
????????????ActionMapping?mapping,
????????????ActionForm?form,
????????????HttpServletRequest?req,
????????????HttpServletResponse?res)
{
????????ProductsForm?pf
= (ProductsForm)form;
????????String?flag
= pf.getFlag();
????????req.setAttribute(
" flag " ,?flag);
????????String?fieldname
= "" ;
????????String?value
= "" ;
????????
if (flag.equals( " 2 " )) {
????????????fieldname
= pf.getFieldname();
????????????value
= pf.getValue();
????????????req.setAttribute(
" fieldname " ,?fieldname);
????????????req.setAttribute(
" value " ,?value);
????????}

????????
????????Products?pd
= new ?Products();
????????pd.setGameCapacity(pf.getGameCapacity());
????????pd.setGameId(pf.getGameId());
????????pd.setGameMedia(pf.getGameMedia());
????????pd.setGameNameCn(pf.getGameNameCn());
????????pd.setGameNameEn(pf.getGameNameEn());
????????pd.setGameVersion(pf.getGameVersion());
????????pd.setGameCopyright(pf.getGameCopyright());
????????pd.setGameContent(pf.getGameContent());
????????
if (pf.getGamePrice().equals( "" )) {
????????????pd.setGamePrice(
null );
????????}
else {
????????????pd.setGamePrice(pf.getGamePrice());
????????}

????????
????????
int ?sign = 1 ;
????????
try {
????????????productsService.addProduct(pd);
????????????sign
= 1 ;
????????}
catch (Exception?e) {
????????????sign
= 2 ;
????????}

????????
????????
if (sign == 1 ) {
????????????
return ?mapping.findForward( " success " );
????????}
else {
????????????
return ?mapping.findForward( " failure " );
????????}

????}

????
????
/**?*/ /** ?
?????*?修改信息
?????
*/

????
public ?ActionForward?doUpdateProduct(
????????????ActionMapping?mapping,
????????????ActionForm?form,
????????????HttpServletRequest?req,
????????????HttpServletResponse?res)
{
????????ProductsForm?pf
= (ProductsForm)form;
????????String?gameId
= pf.getGameId();
????????
????????String?flag
= pf.getFlag();
????????req.setAttribute(
" flag " ,?flag);
????????String?fieldname
= "" ;
????????String?value
= "" ;
????????
if (flag.equals( " 2 " )) {
????????????fieldname
= pf.getFieldname();
????????????value
= pf.getValue();

struts+spring+hibernate的web應用 Web層代碼編寫(1)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲入口 | 日日干夜夜操 | 五月天综合婷婷 | 中文字幕二区 | 欧美日本中文字幕 | a久久| 高潮岳喷我一脸 | 黄色片免费在线播放 | 久久久蜜桃 | 哥斯拉大战金刚2在线观看免费完整版 | v视界成人影院在线视频 | 九九精品激情在线视频 | 国产精品久久国产精品 | 久久草在线| 99久久亚洲精品日本无码 | 亚洲成人激情在线 | 亚洲第一女人av | 成人国产精品免费视频不卡 | 富二代视频污 | a4yy午夜| 国内精品美女久久久久 | 精品国产免费一区二区三区 | 香港三级大全 | 免费一级毛片不卡不收费 | 成人片黄网站A片免费 | 国产在线激情 | 美国三级日本三级久久99 | 日本三级理论 | 国产午夜精品一区二区三区在线观看 | 欧洲精品一区二区三区在线观看 | 日日碰日日操 | 久久vs国产综合色大全 | 日本高清视频在线播放 | 欧美一区在线观看视频 | 国产欧美一区二区成人影院 | 日本阿v无码观看dvd | 丁香六月激情婷婷 | 亚洲一区在线观 | 久萆app污版下载网站 | 天堂av中文字幕 | 日韩精品一区二区在线观看 |