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.jyhon.servlet.user.SignInServlet.java

private boolean verifySignInData(HttpServletRequest request, HttpServletResponse response,
        UserEntity userEntity, VerifyUtil verifyUtil) throws ServletException, IOException {
    Map<String, String> verifyParameter = verifyUtil.verifyParameter(userEntity);
    if (!verifyParameter.isEmpty()) {
        //??/*w ww .  j  a  v  a 2  s.c  o  m*/
        request.setAttribute("verifyParameter", verifyParameter);
        request.getRequestDispatcher("register.jsp").forward(request, response);
        return true;
    }
    return false;
}

From source file:io.github.benas.todolist.web.servlet.todo.UpdateTodoServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String id = request.getParameter("todoId");
    try {/*  w  w  w  . j a  v  a2s.  c o  m*/
        long todoId = Long.parseLong(id);
        Todo todo = todoService.getTodoById(todoId); // FIXME security : may provide an id for a todo of another user!
        request.setAttribute("todo", todo);
        request.getRequestDispatcher(UPDATE_TODO_PAGE).forward(request, response);
    } catch (NumberFormatException e) {
        request.setAttribute("error", MessageFormat.format(resourceBundle.getString("no.such.todo"), id));
        request.getRequestDispatcher(ERROR_PAGE).forward(request, response);
    }
}

From source file:RestrictedService.java

/**
* When the servlet receives a GET request.
*///from  w  w w  .j av a  2  s  .  com
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RequestDispatcher view = request.getRequestDispatcher(SERVICE_JSP);
    view.forward(request, response);
}

From source file:eu.earthobservatory.org.StrabonEndpoint.BrowseBean.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");

    // check connection details
    if (strabonWrapper.getStrabon() == null) {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/connection.jsp");

        // pass the current details of the connection
        request.setAttribute("username", strabonWrapper.getUsername());
        request.setAttribute("password", strabonWrapper.getPassword());
        request.setAttribute("dbname", strabonWrapper.getDatabaseName());
        request.setAttribute("hostname", strabonWrapper.getHostName());
        request.setAttribute("port", strabonWrapper.getPort());
        request.setAttribute("dbengine", strabonWrapper.getDBEngine());

        // pass the other parameters as well
        request.setAttribute("query", request.getParameter("query"));
        request.setAttribute("format", request.getParameter("format"));
        request.setAttribute("handle", request.getParameter("handle"));

        // forward the request
        dispatcher.forward(request, response);

    } else {/*from  w  ww .  j  a  v a  2s  .  com*/

        if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) {
            // HTML visual interface
            processVIEWRequest(request, response);

        } else {// invoked as a service
            processRequest(request, response);
        }
    }
}

From source file:io.github.benas.todolist.web.servlet.todo.SearchServlet.java

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

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

    HttpSession session = request.getSession();
    User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

    List<Todo> todoList = todoService.searchTodoListByTitle(user.getId(), title);
    request.setAttribute("todoList", todoList);

    request.getRequestDispatcher(SEARCH_PAGE).forward(request, response);

}

From source file:net.duckling.ddl.web.interceptor.access.FetchCodeInterceptor.java

private void sendToDoEerror(HttpServletRequest request, HttpServletResponse response, String errorCode)
        throws ServletException, IOException {
    String requestURI = request.getRequestURI();
    String content = request.getContextPath();
    if (StringUtils.isNotEmpty(content)) {
        requestURI = requestURI.substring(content.length());
    }//from  www .jav  a2 s .  co  m
    request.getRequestDispatcher(requestURI + "?func=doError&error=" + errorCode).forward(request, response);
}

From source file:com.orangeandbronze.jblubble.sample.UploadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        pathInfo = "/";
    }/*from  ww  w  .jav a2  s .  c  om*/
    LOGGER.debug("GET {}{}", PATH, pathInfo);
    if ("/create".equals(pathInfo)) {
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/WEB-INF/views/uploads/create.jsp");
        requestDispatcher.forward(request, response);
    } else if (pathInfo.length() > 1) {
        BlobKey blobKey = new BlobKey(pathInfo.substring(1));
        BlobInfo blobInfo = blobstoreService.getBlobInfo(blobKey);
        response.setContentType(blobInfo.getContentType());
        // In Servlet API 3.1, use #setContentLengthLong(long)
        response.setContentLength((int) blobInfo.getSize());
        response.setDateHeader("Last-Modified", blobInfo.getDateCreated().getTime());
        blobstoreService.serveBlob(blobKey, response.getOutputStream());
    } else {
        // else show links to blobs that were previously uploaded (if any)
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/WEB-INF/views/uploads/index.jsp");
        List<BlobInfo> blobInfos = new LinkedList<>();
        for (BlobKey blobKey : blobKeys) {
            blobInfos.add(blobstoreService.getBlobInfo(blobKey));
        }
        request.setAttribute("blobstoreService", blobstoreService);
        request.setAttribute("blobKeys", blobKeys);
        request.setAttribute("blobInfos", blobInfos);
        requestDispatcher.forward(request, response);
    }
}

From source file:com.snapdeal.archive.ArchivalController.java

@RequestMapping("/execute")
public String execute(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String action = request.getParameter("action");
    String batchSize = request.getParameter("batchSize");
    String tableName = request.getParameter("tableName");
    switch (action) {
    case "archive":
        request.getRequestDispatcher("/archivedata/" + tableName + "/" + batchSize).forward(request, response);
        break;//  www.  ja v  a  2  s .com
    case "delete":
        request.getRequestDispatcher("/delete/" + tableName + "/" + batchSize).forward(request, response);
        break;
    case "archieveAndDelete":
        request.getRequestDispatcher("/archive/verify/delete/" + tableName + "/" + batchSize).forward(request,
                response);
        break;
    case "count":
        request.getRequestDispatcher("/count/" + tableName).forward(request, response);
        break;
    default:
        break;
    }

    return "home";
}

From source file:edu.morgan.server.UploadFile.java

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
    // Check that we have a file upload request
    RequestDispatcher rd;//  ww w .j a  v  a2 s  . co  m
    response.setContentType("text/html");

    isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {
        rd = request.getRequestDispatcher("fail.jsp");
        rd.forward(request, response);
    }

    try {
        ServletFileUpload upload = new ServletFileUpload();
        response.setContentType("text/plain");

        FileItemIterator iterator = upload.getItemIterator(request);
        while (iterator.hasNext()) {
            FileItemStream item = iterator.next();
            InputStream stream = item.openStream();
            this.read(stream);
        }
        request.removeAttribute("incompleteStudents");
        request.setAttribute("incompleteStudents", studentList);

        rd = request.getRequestDispatcher("Success");
        rd.forward(request, response);

    } catch (Exception ex) {
        throw new ServletException(ex);
    }

}

From source file:br.org.indt.ndg.servlets.OpenRosaManagement.java

private void dispatchSurveysForUserSelectionPage(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Map<String, String> surveyIdList = m_openRosaBD.getSurveyIdToUrlMap();
    String[] userList = m_openRosaBD.getUserList();
    request.setAttribute(SURVEYS_ATTR, surveyIdList);
    request.setAttribute(USER_IMEI_LIST_ATTR, userList);
    request.getRequestDispatcher(FORWARD_FILEPATH).forward(request, response);
}