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:control.UploadFile.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {/*from  w  ww . j  a v  a2  s  .  c  o  m*/
        boolean ismultipart = ServletFileUpload.isMultipartContent(request);
        if (!ismultipart) {
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);

            List items = null;
            System.out.println(request);
            try {
                items = upload.parseRequest(request);
            } catch (Exception e) {

            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {

                } else {
                    String itemname = item.getName();
                    if (itemname == null || itemname.equals("")) {
                        continue;
                    }
                    String filename = FilenameUtils.getName(itemname);
                    File f = checkExist(filename);
                    item.write(f);
                    request.getRequestDispatcher("/ideaCreated.jsp").forward(request, response);
                }
            }
        }
    } catch (Exception e) {
    } finally {
        out.close();
    }
}

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

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

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

    /* ? */
    String sellerID = Seller.getSellerID();
    String sellerName = request.getParameter("sellerName");
    String sellerTel = request.getParameter("sellerTel");
    String sellerPassword = MD5.GetMD5Code(request.getParameter("sellerPassword"));
    String securityQuestion = request.getParameter("securityQuestion");
    String securityAnswer = request.getParameter("securityAnswer");

    String sellerSql = null;

    if (sellerPassword.equals("")) {
        sellerSql = "update seller set sellerName='" + sellerName + "' ,sellerTel='" + sellerTel
                + "' ,  securityQuestion='" + securityQuestion + "' , securityAnswer='" + securityAnswer
                + "' where sellerID='" + sellerID + "'";
    } else {
        sellerSql = "update seller set sellerName='" + sellerName + "' ,sellerTel='" + sellerTel
                + "', sellerPassword='" + MD5.GetMD5Code(sellerPassword) + "' ,  securityQuestion='"
                + securityQuestion + "' , securityAnswer='" + securityAnswer + "' where sellerID='" + sellerID
                + "'";
    }

    System.out.println("sellerSql: " + sellerSql);
    try {
        statement.executeUpdate(sellerSql);
        getInfo(sellerID);
    } catch (SQLException e) {
        e.printStackTrace();
    }

    System.out.println("--------------------seller modify info-----------------");
    System.out.println();

    request.getSession().removeAttribute("user");
    getInfo(sellerID);
    request.getSession().setAttribute("user", Seller);

    request.getRequestDispatcher("SellerServlet?method=sellerHome&sellerID=" + sellerID).forward(request,
            response);
}

From source file:edu.lternet.pasta.portal.EventSubscribeServlet.java

/**
 * The doPost method of the servlet. <br>
 * /*  www.ja  v  a 2 s  .  c om*/
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession httpSession = request.getSession();
    String uid = (String) httpSession.getAttribute("uid");
    if (uid == null || uid.isEmpty())
        uid = "public";
    String packageId = request.getParameter("packageid");
    String targetUrl = request.getParameter("targeturl");
    String subscription = "<subscription type=\"eml\"><packageId>" + packageId + "</packageId><url>" + targetUrl
            + "</url></subscription>";
    String message = null;
    String type = "info";

    if (uid.equals("public")) {
        message = LOGIN_WARNING;
        type = "warning";
    } else {
        try {
            EventSubscriptionClient eventClient = new EventSubscriptionClient(uid);
            String subscriptionId = eventClient.create(subscription);
            message = String.format("An Event Subscription with identifier '<b>%s</b>' was created.\n",
                    subscriptionId);
        } catch (Exception e) {
            handleDataPortalError(logger, e);
        }
    }

    request.setAttribute("subscribemessage", message);
    request.setAttribute("type", type);
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);
}

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

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

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

    int orderID = Integer.parseInt(request.getParameter("orderID"));
    int state = Integer.parseInt(request.getParameter("state"));
    String sql = "update historyorders set state=" + state + " where orderID=" + orderID + "";
    System.out.println(sql);
    try {
        statement.execute(sql);
    } catch (SQLException e) {
        System.out.println(e.toString());
    }
    if (state == 2) {
        double totalPrice = 0;
        String customerID = null;
        int quantity = 0;
        String dishID = null;
        sql = "Select * from historyorders  where OrderID=" + orderID;

        try {
            resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                totalPrice = Double.parseDouble(resultSet.getString("totalPrice"));
                customerID = resultSet.getString("customerID");
                quantity = resultSet.getInt("quantity");
                dishID = resultSet.getString("dishID");
            }
            String sql2 = "update customer set customerMoney= customerMoney+" + totalPrice
                    + " where customerID='" + customerID + "'";
            statement.execute(sql2);
            String sql3 = "update dishinfo set dishStock= dishStock+" + quantity + " where dishID='" + dishID
                    + "'";
            statement.execute(sql3);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.out.println("------------------dealOrder-----------------");
    System.out.println();

    getOrder(Seller.getSellerID());
    request.getSession().setAttribute("order", SellerOrders);
    request.getRequestDispatcher("SellerServlet?method=sellerOrder&sellerID=" + Seller.getSellerID())
            .forward(request, response);

}

From source file:com.Sor.User.LoginServlet.java

@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        session = request.getSession(true);
        //response.setContentType("text/html");  
        PrintWriter out = response.getWriter();
        String n = request.getParameter("usr");
        String p = request.getParameter("pass");
        System.out.println(n);/*from ww w  . j  a  v a 2s.  c  om*/
        System.out.println(p);

        if (validate(n, p)) {
            String url = "/viewPerson.jsp";
            RequestDispatcher rd = request.getRequestDispatcher(url);
            rd.forward(request, response);
            //HttpServletResponse.sendRedirect(url);
        } else {
            out.print("Sorry. Wrong username or password! ");
        }
        out.close();

    }

From source file:com.log4ic.compressor.utils.Compressor.java

/**
 * ???/*from  w w w .j av  a 2 s  . c  o m*/
 *
 * @param fileUrlList
 * @param request
 * @param response
 * @param type
 * @return
 * @throws com.log4ic.compressor.exception.CompressionException
 *
 */
public static List<SourceCode> mergeCode(String[] fileUrlList, HttpServletRequest request,
        HttpServletResponse response, FileType type) throws CompressionException {
    List<SourceCode> codeList = new FastList<SourceCode>();
    ContentResponseWrapper wrapperResponse = null;
    //???
    for (String url : fileUrlList) {
        int index = url.lastIndexOf(".");
        if (index < 0) {
            continue;
        }
        if (type.contains(url.substring(index + 1))) {
            String fragment;
            try {
                url = URLDecoder.decode(url, "utf8");
            } catch (UnsupportedEncodingException e) {
                throw new CompressionException(e);
            }
            try {
                //http/https ??
                if (HttpUtils.isHttpProtocol(url)) {
                    fragment = importCode(HttpUtils.requestFile(url), url, type, request, response);
                } else {
                    //??
                    if (wrapperResponse == null) {
                        wrapperResponse = new ContentResponseWrapper(response);
                    }
                    request.getRequestDispatcher(url).include(request, wrapperResponse);
                    wrapperResponse.flushBuffer();
                    fragment = wrapperResponse.getContent();
                    fragment = importCode(fragment, url, type, request, response);
                    ((ContentResponseStream) wrapperResponse.getOutputStream()).reset();
                }
            } catch (ServletException e) {
                throw new CompressionException("ServletException", e);
            } catch (IOException e) {
                throw new CompressionException(e);
            } catch (GssParserException e) {
                throw new CompressionException(e);
            } catch (LessException e) {
                throw new CompressionException(e);
            }
            if (StringUtils.isNotBlank(fragment)) {
                codeList.add(new SourceCode(url, fragment));
            }
        }
    }

    if (wrapperResponse != null) {
        try {
            wrapperResponse.close();
        } catch (IOException e) {
            throw new CompressionException(e);
        } catch (Throwable throwable) {
            throw new CompressionException("Close Response error", throwable);
        }
    }
    return codeList;
}

From source file:org.jbpm.formbuilder.server.EmbedingServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String profile = request.getParameter("profile");
    String usr = request.getParameter("usr");
    String pwd = request.getParameter("pwd");
    TaskDefinitionService taskService = createTaskService(request, usr, pwd);
    FormDefinitionService formService = createFormService(request, usr, pwd);
    FormRepresentationEncoder encoder = FormEncodingFactory.getEncoder();
    JsonObject json = new JsonObject();
    json.addProperty("embedded", profile);
    try {/*from w ww . j  a va  2s  .c om*/
        if (profile != null && "guvnor".equals(profile)) {
            String uuid = request.getParameter("uuid");
            String packageName = taskService.getContainingPackage(uuid);
            FormRepresentation form = formService.getFormByUUID(packageName, uuid);
            json.addProperty("uuid", uuid);
            json.addProperty("packageName", packageName);
            if (form != null) {
                json.addProperty("formjson", encoder.encode(form));
            }
        } else {
            throw new Exception("Unknown profile for GET: " + profile);
        }
        request.setAttribute("jsonData", new Gson().toJson(json));
        request.getRequestDispatcher("/FormBuilder.jsp").forward(request, response);
    } catch (TaskServiceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem getting task from guvnor");
    } catch (FormServiceException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem reading form from guvnor");
    } catch (FormEncodingException e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem encoding form");
    } catch (Exception e) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}

From source file:com.megacasting_ppe.web.ServletOffresLibelle.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  w  w . j  a va 2  s  . c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    //on rcupre la valeur recupr du moteur de recherche.
    String Libelle = request.getParameter("libelle_recherche");

    HttpSession session = request.getSession();

    JSONObject global = new JSONObject();
    JSONArray arrayoffre = new JSONArray();

    ArrayList<Offre> listOffresSearch = new ArrayList();
    for (Offre offre : offreDAO.Lister()) {

        if (recherche(offre.getLibelle(), Libelle) > 0) {

            listOffresSearch.add(offre);

        }

    }

    for (Offre offre : listOffresSearch) {

        JSONObject object = new JSONObject();
        object.put("Identifiant", offre.getIdentifiant());
        object.put("Intitule", offre.getLibelle());
        object.put("Reference", offre.getReference());
        object.put("DateDebutContrat", offre.getDateDebutContrat().toString());
        object.put("NombresPoste", offre.getNbPoste());
        object.put("VilleEntreprise", offre.getClient().getVilleEntreprise());
        arrayoffre.add(object);

    }
    global.put("offres", arrayoffre);
    global.put("container_search", Libelle);
    session.setAttribute("offres_lib", global);

    RequestDispatcher rq = request.getRequestDispatcher("offres.html");
    rq.forward(request, response);

}

From source file:edu.isi.pfindr.servlets.QueryServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *//*from  w  w w  .  j ava 2 s  .co m*/
@SuppressWarnings("unchecked")
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    HttpSession session = request.getSession(false);
    String action = request.getParameter("action");
    boolean mustchange = (Boolean) session.getAttribute("mustchange");
    if (mustchange) {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/resources/PasswordChange.jsp");
        dispatcher.forward(request, response);
    } else if (action != null && action.equals("history")) {
        ArrayList<JSONObject> history = (ArrayList<JSONObject>) session.getAttribute("history");
        ArrayList<String> rows = new ArrayList<String>();
        for (int i = 0; i < history.size(); i++) {
            rows.add(Utils.decodeQueryHTML(history.get(i)));
        }
        request.setAttribute("history", rows);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/resources/History.jsp");
        dispatcher.forward(request, response);
    } else if (action != null && action.equals("getQueries")) {
        getBookmarks(request, (Connection) session.getAttribute("conn"));
        RequestDispatcher dispatcher = request.getRequestDispatcher("/resources/Bookmarks.jsp");
        dispatcher.forward(request, response);
    } else if (action != null && action.equals("getBookmark")) {
        getBookmarks(request, (Connection) session.getAttribute("conn"));
        // set the bookmark query in the session
        setBookmarkQuery(request, (Connection) session.getAttribute("conn"));
        response.sendRedirect("/pfindr/query");
    } else if (action != null && action.equals("getHistory")) {
        // set the history query in the session
        int bookmark = Integer.parseInt(request.getParameter("qid"));
        session.setAttribute("query", ((ArrayList<JSONObject>) session.getAttribute("history")).get(bookmark));
        response.sendRedirect("/pfindr/query");
    } else if (action != null && action.equals("homepage")) {
        // go to the HOME Page
        RequestDispatcher dispatcher = request.getRequestDispatcher("/resources/PhenoExplorer.jsp");
        dispatcher.forward(request, response);
    } else {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/resources/Query.jsp");
        dispatcher.forward(request, response);
    }
}

From source file:com.edgenius.wiki.webapp.servlet.InstallServlet.java

private void updateLicense(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String license = StringUtils.trimToEmpty(request.getParameter("license"));
    if (license != "") {
        //validate license
        if (LicenseManager.verfiyLicense(license, Version.exist_user_amout) != 0) {
            request.setAttribute("error", "Invalid license, please verify your input.");
            //echo back message
            request.setAttribute("license", license);
            request.getRequestDispatcher("/WEB-INF/pages/install/license-expired.jsp").forward(request,
                    response);/*from   ww  w  .  j  a v  a  2 s .c  om*/
            return;
        }

        //save valid license
        Installation install = Installation.refreshInstallation();
        install.setLicense(license);
        Installation.saveInstallation(install);

        //here will reload context and refresh Version class static varaibles
        installDone(request, response);
        response.sendRedirect(WebUtil.getHostAppURL());
    } else {
        request.getRequestDispatcher("/WEB-INF/pages/install/license-expired.jsp").forward(request, response);
    }

}