⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchitemaction.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
/*
 * @author                        : Neelesh
 * @Version                       : 1.0
 *
 * Development Environment        : Oracle9i JDeveloper
 * Name of the File               : SearchItemAction.java
 * Creation/Modification History  :
 *
 * Neelesh   14-Jan-2003      Created
 *
 */
package oracle.otnsamples.vsm.actions.mall;


// Servlet,IO and Collections API
import java.io.IOException;

import java.util.HashMap;

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

import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.services.MallNavigation;
import oracle.otnsamples.vsm.services.MallNavigationHome;
import oracle.otnsamples.vsm.services.ServiceException;
import oracle.otnsamples.vsm.services.data.Item;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;


/**
 * The action class stores the results of an item search in the request Extends
 * HomePageAction class for information about cart and navigation details
 *
 * @author Neelesh
 * @version 1.0
 */
public class SearchItemAction extends HomePageAction {
  /**
   * This is the action called from the Struts framework to display the results
   * of item search
   *
   * @param <b>mapping</b> The ActionMapping used to select this instance.
   * @param <b>form</b> The optional ActionForm bean for this request.
   * @param <b>request</b> The HTTP Request we are processing.
   * @param <b>response</b> The HTTP Response we are processing.
   *
   * @return <b>ActionForward</b> The  control forward information
   *
   * @throws <b>IOException</b>
   * @throws <b>ServletException</b>
   */
  public ActionForward execute(
                               ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
                               throws IOException, ServletException {

    // adds navigation related data to request
    super.execute(mapping, form, request, response);

    MallNavigationHome navigationHome =
      (MallNavigationHome) ServiceLocator.getLocator().getService("MallNavigation");
    MallNavigation navigation = null;

    try {
      navigation = navigationHome.create();

      // The item data needed for the search results page
      String langID = getLocale(request).getLanguage();
      HashMap map   = new HashMap();
      // Get the items matching the search keyword 
      Item[] items  =
        navigation.searchItem(request.getParameter("keyword"), langID);
      request.setAttribute("items", items);
      // create a table of shop id v/s shop name,
      // this table is used in the JSP to display shop names
      for(int i = items.length - 1; i >= 0; i--) {

        if(!map.containsKey(items [ i ].getShopID())) {
          map.put(
                  items [ i ].getShopID(),
                  navigation.getShop(items [ i ].getShopID(), langID)
                            .getShopDetail(langID).getShopName());
        }
      }

      request.setAttribute("shops", map);
      // search results message
      ActionMessages messages = new ActionMessages();
      if(items==null || items.length==0){
        messages.add("ResultMessage",new ActionMessage("message.noresults"));
      }else{
        messages.add("ResultMessage",new ActionMessage("message.searchlength",
                                     request.getParameter("keyword"),
                                       "" + items.length));
      }
      saveMessages(request, messages);
    } catch(ServiceException ex) {
      // handle errors
      servlet.log("SearchItemError", ex);      
      ActionErrors errors = new ActionErrors();
      errors.add(
                 "SearchError",
                 new ActionError(
                                 "error.searchaction",
                                 MessageCache.getMessage(
                                                         ex.getMessageCode(),
                                                         getLocale(request))));
      saveErrors(request, errors);
    } catch(Exception ex) {
      // handle errors
      servlet.log("SearchItemError", ex);      
      ActionErrors errors = new ActionErrors();
      errors.add("SearchError", new ActionError("error.searchaction"));
      saveErrors(request, errors);
    } finally {

      if(navigation != null) {

        try {
          navigation.remove();
        } catch(Exception ex) {
        }
      }
    }
    return mapping.findForward("success");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -