Example usage for javax.servlet.http HttpServletRequest getRequestDispatcher

List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRequestDispatcher.

Prototype

public RequestDispatcher getRequestDispatcher(String path);

Source Link

Document

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Usage

From source file:com.netcracker.financeapp.controller.income.IncomeServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int value = Integer.parseInt(request.getParameter("value"));

    Date date = null;/*from w  w w . java2 s .  c o  m*/
    try {
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        date = dateFormat.parse(request.getParameter("date"));
    } catch (ParseException ex) {
        Logger.getLogger(IncomeServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    String description = request.getParameter("description");
    String typeName = request.getParameter("incomeType");
    int typeId = typeService.getTypeByName(typeName).getIdType();

    int transactionTypeId = typeService.getTypeByName(typeName).getIdParent();
    int stateTypeId = typeService.getTypeByName("COMMITED").getIdType();

    String from = request.getParameter("fromListVal");
    Agent currentAgent = agentService.getAgentByName(from);

    String to = request.getParameter("toListVal");
    BankCard currentBankCard = bankCardService.getBankCardByNumber(to);
    bankCardService.editCardAmount(currentBankCard.getIdCard(), currentBankCard.getAmount() + value);

    int incomeId = incomeService.insertIncome(value, description, date, typeId);
    if (incomeId > 0) {
        request.getRequestDispatcher("templates/success.jsp").forward(request, response);
        transactionService.insertTransaction(transactionTypeId, stateTypeId, currentAgent.getIdAgent(),
                currentBankCard.getIdCard(), incomeId);
    } else {
        request.getRequestDispatcher("templates/error.jsp").forward(request, response);
    }
}

From source file:com.lrodriguez.SVNBrowser.java

private void doBrowserDateQuery(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        Date startDate, Date endDate, String pFileType, String currentBranch, Comparator comparator)
        throws ServletException, IOException {
    logDebug("dispatching Browser Date query");

    List uniqueEntries = getUniqueEntries(request, startDate, endDate);
    if (request.getAttribute(ERROR) != null) {
        request.getRequestDispatcher(INDEX_JSP).forward(request, response);
        return;//from w w  w  . ja v a2  s . c  o m
    }

    uniqueEntries = filterListByDateRange(uniqueEntries, startDate, endDate);
    uniqueEntries = filterListByFileType(uniqueEntries, pFileType);
    uniqueEntries = filterListByCurrentBranch(uniqueEntries, currentBranch);

    Collections.sort(uniqueEntries, comparator);

    session.setAttribute(UNIQUE_ENTRIES, uniqueEntries);
    request.getRequestDispatcher(INDEX_JSP).forward(request, response);
    return;
}

From source file:com.lrodriguez.SVNBrowser.java

private void doSvnRevisionQuery(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logDebug("dispatching Revision SVN query request");
    List entriesList = getUniqueEntries(request, Long.parseLong(request.getParameter(START_REVISION)),
            Long.parseLong(request.getParameter(END_REVISION)));//get all files in date range
    if (request.getAttribute(ERROR) != null) {
        request.getRequestDispatcher(INDEX_JSP).forward(request, response);
        return;/*from   w  w  w  . jav  a 2s  . c  om*/
    }
    sortAndFilterSvnQuery(request, response, entriesList);
    return;
}

From source file:com.darksky.seller.SellerServlet.java

/**
 * ??//from  w ww.ja va  2 s .  c  o  m
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 * @throws ParseException
 */
public void sellerShop(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ParseException {
    System.out.println();
    System.out.println("----------------------sellerShop------------");

    if (!LoginState) {
        request.getRequestDispatcher("HomeServlet?method=showShops.jsp").forward(request, response);
        return;
    }

    getShop(Seller.getShopID());
    request.getSession().setAttribute("shop", Shop);

    System.out.println("----------------------sellerShop------------");
    System.out.println();

    request.getRequestDispatcher(".jsp").forward(request, response);

}

From source file:cn.itcast.bbs.controller.BbsServlet.java

private void showAllTopic(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*www.j a v  a2  s  . co  m*/
        int id = Integer.parseInt(request.getParameter("typeId"));
        //??
        List<Topic> topicList = service.showAllTopicByTypeId(id);
        request.setAttribute("topicList", topicList);
        request.setAttribute("typeId", id);
        //
        HttpSession session = request.getSession();
        if (!session.isNew()) {
            List<Integer> typeIdList = (List<Integer>) session.getAttribute("typeIdList");
            if (typeIdList == null) {
                typeIdList = new ArrayList<Integer>();
                session.setAttribute("typeIdList", typeIdList);
            }
            boolean flag = service.isClicked(id, typeIdList);
            if (!flag) {
                service.updateTypeClick(id);
            }
        }
        request.getRequestDispatcher("/WEB-INF/bbs/listAllTopic.jsp").forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
        request.setAttribute("message", "?");
        request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response);
    }
}

From source file:com.darksky.seller.SellerServlet.java

/**
 * *  //from w w w.jav a  2 s . c o m
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
public void openShop(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println();
    System.out.println("-----------------open shop-----------");

    if (!LoginState) {
        request.getRequestDispatcher("HomeServlet?method=showShops").forward(request, response);
        return;
    }

    String shopName = request.getParameter("shopName");
    String shopIntroduction = request.getParameter("shopIntroduction");
    String shopID = request.getParameter("shopID");
    String shopType = request.getParameter("shopType");
    String shopAddress = request.getParameter("shopAddress");
    String shopLicense = request.getParameter("shopLicense");

    String shopSql = "insert into shop (shopID,shopName,shopTel,shopType,shopAddress,shopLicense,shopIntroduction) values('"
            + shopID + "','" + shopName + "','" + shopID + "','" + shopType + "','" + shopAddress + "','"
            + shopLicense + "','" + shopIntroduction + "')";
    String sellerSql = "update seller set shopId='" + shopID + "' where sellerID ='" + Seller.getSellerID()
            + "'";

    System.out.println("shopSql: " + shopSql);
    System.out.println("sellerSql: " + sellerSql);
    try {
        statement.execute(shopSql);
        statement.execute(sellerSql);
    } catch (SQLException e) {
        e.printStackTrace();

        System.out.println("open shop fail");

        request.getSession().setAttribute("openshop", "fail");
        request.getRequestDispatcher("?.jsp").forward(request, response);
    }
    System.out.println("open shop success");

    System.out.println("-----------------open shop-----------");
    System.out.println();

    request.getSession().setAttribute("sellerShop", "0");
    request.getRequestDispatcher("SellerServlet?method=sellerHome&sellerID=" + Seller.getSellerID())
            .forward(request, response);
}

From source file:com.darksky.seller.SellerServlet.java

/**
 * ??/*from w  w  w  .  j a v  a  2s.co  m*/
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 * @throws ParseException
 */
public void sellerOrder(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ParseException {
    System.out.println();
    System.out.println("----------------------sellerOrder------------");

    if (!LoginState) {
        request.getRequestDispatcher("HomeServlet?method=showShops.jsp").forward(request, response);
        return;
    }

    String sellerID = request.getParameter("sellerID");

    /* ?? */
    getOrder(sellerID);
    request.getSession().setAttribute("orders", SellerOrders);

    System.out.println("----------------------sellerOrder------------");
    System.out.println();

    request.getRequestDispatcher("??.jsp").forward(request, response);

}

From source file:com.darksky.seller.SellerServlet.java

/**
 *  ??//from  w w w.ja  va  2  s  .c  o m
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 * @throws ParseException
 */
public void sellerDish(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, ParseException {
    System.out.println();
    System.out.println("----------------------sellerDish------------");

    if (!LoginState) {
        request.getRequestDispatcher("HomeServlet?method=showShops").forward(request, response);
        return;
    }

    String sellerID = request.getParameter("sellerID");
    System.out.println("**********************     sellerID=    " + sellerID + "**************");

    /* ? */
    getDish(sellerID);
    request.getSession().setAttribute("dish", DishList);

    System.out.println("----------------------sellerDish------------");
    System.out.println();

    request.getRequestDispatcher("?.jsp").forward(request, response);

}

From source file:com.darksky.seller.SellerServlet.java

/**
 * * ? /*from   w  w  w. j a  va  2  s . c  o  m*/
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
public void deleteDish(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println();
    System.out.println("-------------------delete dish-----------------");

    if (!LoginState) {
        request.getRequestDispatcher("HomeServlet?method=showShops").forward(request, response);
        return;
    }

    String dishID = request.getParameter("dishID");
    String sellerID = request.getParameter("sellerID");
    String sql = "delete from dishinfo where dishID='" + dishID + "' and sellerId = '" + sellerID + "'";
    System.out.println(sql);
    boolean Bdelete = false;
    try {
        statement.execute(sql);
        Bdelete = true;
    } catch (SQLException e) {
        System.out.println(e.toString());
    }
    if (Bdelete) {
        System.out.println("delete dish success");
        // request.setAttribute("delState", true);
    } else {
        System.out.println("delete dish fail");
        // request.setAttribute("delState", false);
    }

    System.out.println("-------------------delete dish-----------------");
    System.out.println();

    getDish(sellerID);
    request.getSession().setAttribute("dish", DishList);
    request.getRequestDispatcher("?.jsp").forward(request, response);

}

From source file:cn.vlabs.duckling.vwb.VWBDriverServlet.java

public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    URLParser info = URLParser.getParser(request);
    if (info.hasMoreSlash()) {
        response.sendRedirect(buildURL(info, request));
        return;/*from   w ww.j a  v  a2s. c  o  m*/
    }
    SiteMetaInfo site = findSiteById(request, info.getSiteId());

    if (site == null) {
        site = findSiteByDomain(request);
    }

    if (site == null) {
        log.info("Neither site find by site id or domain. redirect to default site.");
        site = container.getSite(VWBContainer.ADMIN_SITE_ID);
        response.sendRedirect(getFrontPage(request));
        return;
    }
    if (requireRedirect(request, info, site.getId())) {
        response.sendRedirect(getFrontPage(request));
        return;
    }

    if (info.isPlainURL()) {
        // Plain URL just forward.
        // support for Site id based url (login/logout/JSON-RPC etc.).
        if (info.getPage() != null) {
            RequestDispatcher dispatcher = request.getRequestDispatcher(info.getPage());
            dispatcher.forward(request, response);
            return;
        }
    }

    if (info.isSimpleURL()) {
        processSimpleURL(info, request, response);
        return;
    }

    if (info.getPage() == null) {
        response.sendRedirect(getFrontPage(request));
        return;
    }
    // Proceeding viewport...
    int vid = Constant.DEFAULT_FRONT_PAGE;

    vid = Integer.parseInt(info.getPage());
    Resource vp = VWBContainerImpl.findContainer().getResourceService().getResource(site.getId(), vid);
    if (vp == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    try {
        if (showWelcome(request, site, vid)) {
            vid = Constant.WELCOME_FRONT_PAGE;
            vp = VWBContainerImpl.findContainer().getResourceService().getResource(site.getId(), vid);
        }
    } catch (NumberFormatException e) {
        response.sendRedirect(getFrontPage(request));
        return;
    }

    request.setAttribute("contextPath", request.getContextPath());
    try {
        IRequestMapper mapper = container.getMapFactory().getRequestMapper(vp.getType());
        if (mapper != null) {
            log.debug(vp.getType() + " is requested.");
            fetcher.saveToSession(request);
            mapper.map(vp, info.getParams(), request, response);
        } else {
            log.debug("not support type is requested.");
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

    } catch (ServletException e) {
        if (e.getRootCause() != null) {
            sendError(request, response, e.getRootCause());
        } else
            sendError(request, response, e);
    } catch (Throwable e) {
        sendError(request, response, e);
    }
}