Example usage for javax.servlet RequestDispatcher forward

List of usage examples for javax.servlet RequestDispatcher forward

Introduction

In this page you can find the example usage for javax.servlet RequestDispatcher forward.

Prototype

public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;

Source Link

Document

Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.

Usage

From source file:mashups.eventpub.EventPublisherServlet.java

/**
 * Output list of columns in chosen worksheet
 *
 * @param request The request /*from  w ww.ja v a 2 s.c  o  m*/
 * @param response The response 
 */
private void processOutputColumnList(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EventPublisher ep = new EventPublisher();
    try {
        ep.setSsAuthSubToken((String) request.getSession().getAttribute(SESSION_ATTR_SS_AUTH_TOKEN), false);
        request.setAttribute("token", ep.getSsAuthSubToken());
        request.setAttribute("columnList", ep.getColumnList((String) request.getParameter("cellFeed")));
        request.getSession().setAttribute(SESSION_ATTR_SS_CELL_FEED, (String) request.getParameter("cellFeed"));
    } catch (EPAuthenticationException e) {
        System.err.println("Authentication exception: " + e.getMessage());
    }

    RequestDispatcher dispatcher = getServletContext()
            .getRequestDispatcher("/WEB-INF/jsp/outputColumnList.jsp");
    dispatcher.forward(request, response);
}

From source file:at.gv.egiz.bku.online.webapp.UIServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    BindingProcessorManager bindingProcessorManager = (BindingProcessorManager) getServletContext()
            .getAttribute("bindingProcessorManager");
    if (bindingProcessorManager == null) {
        String msg = "Configuration error: BindingProcessorManager missing!";
        log.error(msg);//w ww. j  a  v a  2 s  .  c  o  m
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
        return;
    }

    Configuration conf = ((BindingProcessorManagerImpl) bindingProcessorManager).getConfiguration();
    if (conf == null)
        log.error("No configuration");
    else
        MoccaParameterBean.setP3PHeader(conf, resp);

    Id id = (Id) req.getAttribute("id");
    BindingProcessor bindingProcessor = null;
    if (id == null || !((bindingProcessor = bindingProcessorManager
            .getBindingProcessor(id)) instanceof HTTPBindingProcessor)) {
        resp.sendRedirect(expiredPageUrl);
        return;
    }

    MoccaParameterBean parameterBean = new MoccaParameterBean((HTTPBindingProcessor) bindingProcessor);
    req.setAttribute("moccaParam", parameterBean);

    String uiPage = MoccaParameterBean.getInitParameter("uiPage", getServletConfig(), getServletContext());
    uiPage = parameterBean.getUIPage(uiPage);
    if (uiPage == null) {
        uiPage = "applet.jsp";
    }

    RequestDispatcher dispatcher = req.getRequestDispatcher(uiPage);
    if (dispatcher == null) {
        log.warn("Failed to get RequestDispatcher for page {}.", uiPage);
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {
        dispatcher.forward(req, resp);
    }

}

From source file:eu.eidas.node.connector.CountrySelectorServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    /**//from w w  w . ja  v  a 2  s .co m
     * List of supported countries.
     */
    List<Country> countries;

    /**
     * SAML token containing a request.
     */
    String sAMLRequest;

    /**
     * Id of the providerName.
     */
    String providerName = null;

    /**
     * URL of the SP.
     */
    String spUrl;

    try {

        AUCONNECTORUtil auConnectorUtil = ApplicationContextProvider.getApplicationContext()
                .getBean(AUCONNECTORUtil.class);
        if (auConnectorUtil != null && auConnectorUtil.getConfigs() != null
                && null != auConnectorUtil.getConfigs()
                        .getProperty(EIDASValues.EIDAS_CONNECTOR_SUPPORT_FRAMING_REQUEST.toString())
                && !Boolean.parseBoolean(auConnectorUtil.getConfigs()
                        .getProperty(EIDASValues.EIDAS_CONNECTOR_SUPPORT_FRAMING_REQUEST.toString()))) {
            RequestDispatcher dispatcher = getServletContext()
                    .getRequestDispatcher(NodeViewNames.EIDAS_CONNECTOR_COUNTRY_FRAMING.toString());
            dispatcher.forward(request, response);
            return;
        }
        // Prevent cookies from being accessed through client-side script.
        setHTTPOnlyHeaderToSession(false, request, response);

        // Obtaining the assertion consumer url from SPRING context
        ConnectorControllerService controllerService = (ConnectorControllerService) getApplicationContext()
                .getBean(NodeBeanNames.EIDAS_CONNECTOR_CONTROLLER.toString());
        LOG.trace(controllerService.toString());

        final Map<String, String> parameters = getHttpRequestParameters(request);

        // Validate HTTP Parameter SP URL
        EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                EIDASParameters.SP_URL.toString(), parameters.get(EIDASParameters.SP_URL.toString()),
                EIDASErrors.SP_COUNTRY_SELECTOR_INVALID_SPURL);

        spUrl = parameters.get(EIDASParameters.SP_URL.toString());
        request.getSession().setAttribute(EIDASParameters.SP_URL.toString(), spUrl);
        parameters.put(EIDASParameters.ERROR_REDIRECT_URL.toString(), spUrl);
        controllerService.getSession().put(EIDASParameters.ERROR_REDIRECT_URL.toString(), spUrl);

        // Validate HTTP Parameter attrList
        EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                EIDASParameters.ATTRIBUTE_LIST.toString(),
                parameters.get(EIDASParameters.ATTRIBUTE_LIST.toString()),
                EIDASErrors.SP_COUNTRY_SELECTOR_INVALID_ATTR);

        // Validate HTTP Parameter SP QAALevel
        EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                EIDASParameters.SP_QAALEVEL.toString(), parameters.get(EIDASParameters.SP_QAALEVEL.toString()),
                EIDASErrors.SP_COUNTRY_SELECTOR_INVALID_SPQAA);

        // Validate HTTP Parameter SP ID
        EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                EIDASParameters.SP_ID.toString(), parameters.get(EIDASParameters.SP_ID.toString()),
                EIDASErrors.SP_COUNTRY_SELECTOR_INVALID_SPID);

        // Validate HTTP Parameter ProviderName
        if (StringUtils.isNotEmpty(providerName)) {
            EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                    EIDASParameters.PROVIDER_NAME_VALUE.toString(),
                    parameters.get(EIDASParameters.PROVIDER_NAME_VALUE.toString()),
                    EIDASErrors.SP_COUNTRY_SELECTOR_INVALID_PROVIDER_NAME);
        }

        final byte[] samlToken = controllerService.getConnectorService().processCountrySelector(parameters);

        countries = controllerService.getConnectorService().getCountrySelectorList();

        LOG.debug("Countries: " + countries.toString());
        sAMLRequest = EIDASUtil.encodeSAMLToken(samlToken);
        EIDASUtil.validateParameter(CountrySelectorServlet.class.getCanonicalName(),
                EIDASParameters.SAML_REQUEST.toString(), sAMLRequest,
                EIDASErrors.SP_COUNTRY_SELECTOR_ERROR_CREATE_SAML);

        request.setAttribute(EIDASParameters.EIDAS_AUTH_CONSENT.toString(), controllerService.getNodeAuth());
        request.setAttribute(EIDASParameters.SAML_REQUEST.toString(), sAMLRequest);
        request.setAttribute(EIDASParameters.SP_METADATA_URL.toString(),
                parameters.get(EIDASParameters.SP_METADATA_URL.toString()));
        request.setAttribute("countries", countries);

        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(NodeViewNames.EIDAS_CONNECTOR_COUNTRY_SELECTOR.toString());
        dispatcher.forward(request, response);

    } catch (AbstractEIDASException e) {
        LOG.info("BUSINESS EXCEPTION : country selector servlet", e.getErrorMessage());
        LOG.debug("BUSINESS EXCEPTION : country selector servlet", e);
        throw e;
    }
}

From source file:com.larasolution.serverlts.FileUploadHandler.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //     tablename=request.getParameter(tablename)
    //process only if its multipart content
    FileOutputStream fos = new FileOutputStream("C:\\uploads\\data.csv");
    String list = "";
    List<List> allData = new ArrayList<List>();

    List<String> parameters = new ArrayList<String>();
    if (ServletFileUpload.isMultipartContent(request)) {

        try {/*from  w w w  . jav a  2s .  c  o  m*/

            StringBuilder data = new StringBuilder();
            List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
            System.out.println(multiparts);
            for (FileItem item : multiparts) {
                if (item.isFormField()) {
                    parameters.add(item.getFieldName());
                    System.out.println(parameters);
                }
                if (!item.isFormField()) {
                    String name = new File(item.getName()).getName();

                    item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
                    //System.out.println(File.separator);
                    // Get the workbook object for XLSX file
                    XSSFWorkbook wBook = new XSSFWorkbook(
                            new FileInputStream(UPLOAD_DIRECTORY + File.separator + name));

                    XSSFSheet zz = wBook.getSheetAt(0);
                    FormulaEvaluator formulaEval = wBook.getCreationHelper().createFormulaEvaluator();

                    Row row;
                    Cell cell;

                    // Iterate through each rows from first sheet
                    Iterator<Row> rowIterator = zz.iterator();
                    while (rowIterator.hasNext()) {
                        row = rowIterator.next();

                        // For each row, iterate through each columns
                        Iterator<Cell> cellIterator = row.cellIterator();

                        while (cellIterator.hasNext()) {

                            cell = cellIterator.next();

                            switch (cell.getCellType()) {
                            case Cell.CELL_TYPE_BOOLEAN:
                                data.append(cell.getBooleanCellValue()).append(",");
                                break;
                            case Cell.CELL_TYPE_NUMERIC:
                                if (DateUtil.isCellDateFormatted(cell)) {
                                    data.append(
                                            com.larasolution.modle.getDate.getDate5(cell.getDateCellValue()))
                                            .append(",");
                                } else {
                                    data.append(cell.getNumericCellValue()).append(",");
                                }

                                break;
                            case Cell.CELL_TYPE_STRING:
                                data.append(cell.getStringCellValue()).append(",");
                                break;
                            case Cell.CELL_TYPE_BLANK:
                                data.append("" + ",");
                                break;
                            case Cell.CELL_TYPE_FORMULA:
                                Double value = Double.parseDouble(formulaEval.evaluate(cell).formatAsString());

                                data.append(String.format("%.2f", value)).append(",");
                                break;
                            default:
                                data.append(cell).append("");

                            }

                        }
                        data.append("\r\n");
                        //String k = data.substring(0, data.length() - 3);
                        //ls.add(k);

                        // data.setLength(0);
                    }

                    fos.write(data.toString().getBytes());
                    fos.close();

                    //
                }
            }

            savetosql();
            request.setAttribute("message", "successfully uploaded ");
        } catch (Exception ex) {
            request.setAttribute("message", "File Upload Failed due to " + ex);
        }

    } else {
        request.setAttribute("message", "Sorry this Servlet only handles file upload request");
    }

    request.setAttribute("arrayfile", allData);
    request.setAttribute("names", parameters);
    RequestDispatcher disp = getServletContext().getRequestDispatcher("/FileUploadResult.jsp");
    disp.forward(request, response);

    // System.out.println(allData.size());
    // response.sendRedirect("send.jsp?arrayfile=" + list + "");
    //request.getRequestDispatcher("/send.jsp?arrayfile='"+ls+"'").forward(request, response);
}

From source file:com.centurylink.mdw.hub.servlet.RestServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    CodeTimer timer = new CodeTimer("RestServlet.doGet()", true);

    if (request.getPathInfo() == null) {
        // redirect to html documentation
        response.sendRedirect(ApplicationContext.getMdwHubUrl() + "/doc/webServices.html");
        return;//from w  w w . j ava  2  s.  c o  m
    } else if (request.getPathInfo().startsWith("/SOAP")) {
        // forward to SOAP servlet
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getPathInfo());
        requestDispatcher.forward(request, response);
        return;
    } else if (ApplicationContext.isDevelopment() && isFromLocalhost(request)) {
        // this is only allowed from localhost and in dev
        if ("/System/exit".equals(request.getPathInfo())) {
            response.setStatus(200);
            new Thread(new Runnable() {
                public void run() {
                    System.exit(0);
                }
            }).start();
            return;
        }
    }

    Map<String, String> metaInfo = buildMetaInfo(request);
    try {
        String responseString = handleRequest(request, response, metaInfo);

        String downloadFormat = metaInfo.get(Listener.METAINFO_DOWNLOAD_FORMAT);
        if (downloadFormat != null) {
            response.setContentType(Listener.CONTENT_TYPE_DOWNLOAD);
            String fileName = request.getPathInfo().substring(1).replace('/', '-') + "." + downloadFormat;
            response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
            if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_JSON)
                    || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_XML)
                    || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_TEXT)) {
                response.getOutputStream().write(responseString.getBytes());
            } else if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_FILE)) {
                String f = metaInfo.get(Listener.METAINFO_DOWNLOAD_FILE);
                if (f == null)
                    throw new ServiceException(ServiceException.INTERNAL_ERROR, "Missing meta");
                File file = new File(f);
                if (!file.isFile())
                    throw new ServiceException(ServiceException.NOT_FOUND,
                            "File not found: " + file.getAbsolutePath());
                int max = PropertyManager.getIntegerProperty(PropertyNames.MAX_DOWNLOAD_BYTES, 104857600);
                if (file.length() > max)
                    throw new ServiceException(ServiceException.NOT_ALLOWED,
                            file.getAbsolutePath() + " exceeds max download size (" + max + "b )");
                response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\"");
                try (InputStream in = new FileInputStream(file)) {
                    int read = 0;
                    byte[] bytes = new byte[8192];
                    while ((read = in.read(bytes)) != -1)
                        response.getOutputStream().write(bytes, 0, read);
                }
            } else {
                // for binary content string response will have been Base64 encoded
                response.getOutputStream().write(Base64.decodeBase64(responseString.getBytes()));
            }
        } else {
            if ("/System/sysInfo".equals(request.getPathInfo())
                    && "application/json".equals(metaInfo.get(Listener.METAINFO_CONTENT_TYPE))) {
                responseString = WebAppContext.addContextInfo(responseString, request);
            }
            response.getOutputStream().write(responseString.getBytes());
        }
    } catch (ServiceException ex) {
        logger.severeException(ex.getMessage(), ex);
        response.setStatus(ex.getCode());
        response.getWriter().println(createErrorResponseMessage(request, metaInfo, ex));
    } finally {
        timer.stopAndLogTiming("");
    }
}

From source file:eu.impact_project.iif.t2.client.WorkflowParser.java

/**
 * Analyzes the uploaded workflow files for input names and input depths
 *//*  w w w .  j  a v a  2  s  .  co  m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession session = request.getSession(true);

    List<Workflow> workflows = new ArrayList<Workflow>();

    Map<String, String> htmlFormItems = Helper.parseRequest(request);

    int k = 0;
    while (htmlFormItems.get("currentTab" + k) != null) {
        session.setAttribute("currentTab" + k, htmlFormItems.get("currentTab" + k));
        k++;
    }

    // kind of a hack, because nested forms are not allowed.
    // some parameters are copied to attributes and the servlet for
    // selecting a group is called
    if (htmlFormItems.get("selectGroup") != null) {

        int i = 0;
        while (htmlFormItems.get("MyExpGroup" + i) != null) {
            request.setAttribute("MyExpGroup" + i, htmlFormItems.get("MyExpGroup" + i));
            i++;
        }

        int j = 0;
        while (htmlFormItems.get("MyExpWorkflow" + j) != null) {
            request.setAttribute("MyExpWorkflow" + j, htmlFormItems.get("MyExpWorkflow" + j));
            j++;
        }

        RequestDispatcher rd0 = getServletContext().getRequestDispatcher("/GroupSelector");
        rd0.forward(request, response);
        return;

        // here is the original servlet functionality
    } else {

        int i = 0;
        while (htmlFormItems.get("file_workflow" + i) != null
                || htmlFormItems.get("MyExpWorkflow" + i) != null) {
            String workflowFile = htmlFormItems.get("file_workflow" + i);
            String workflowUrl = htmlFormItems.get("MyExpWorkflow" + i);

            if (workflowFile != null && !workflowFile.equals("")) {
                Workflow currentWorkflow = parseWorkflow(workflowFile);
                workflows.add(currentWorkflow);
            } else if (workflowUrl != null && !workflowUrl.equals("")) {
                String urlString = "http://www.myexperiment.org/workflow.xml?id=" + workflowUrl
                        + "&elements=content";

                String user = (String) session.getAttribute("user");
                String password = (String) session.getAttribute("password");

                HttpClient client = Helper.createAuthenticatingClient("www.myexperiment.org", user, password);

                // GET method to retrieve the chosen workflow which is
                // base64
                // encoded and wrapped in xml
                GetMethod get = new GetMethod(urlString);
                get.setDoAuthentication(true);

                client.executeMethod(get);
                // get the xml
                InputStream responseBody = get.getResponseBodyAsStream();

                try {
                    SAXBuilder builder = new SAXBuilder();
                    Document doc = builder.build(responseBody);

                    Element root = doc.getRootElement();
                    // the content element contains the workflow
                    String workflowBase64 = root.getChild("content").getTextTrim();

                    // decode the workflow and convert to string
                    byte[] bytes = Base64.decodeBase64(workflowBase64.getBytes());
                    String workflowString = new String(bytes);

                    // make a Workflow instance which will be used in the frontend
                    Workflow currentWorkflow = parseWorkflow(workflowString);
                    workflows.add(currentWorkflow);

                    session.setAttribute("currentWfId" + i, workflowUrl);

                } catch (JDOMException e) {
                    e.printStackTrace();
                }
            }
            i++;
        }
    }

    // controls the "show examples" checkbox in the jsp
    if (htmlFormItems.get("printExamples") != null) {
        session.setAttribute("printExamples", Boolean.TRUE);
    } else {
        session.setAttribute("printExamples", Boolean.FALSE);
    }

    session.setAttribute("workflows", workflows);
    request.setAttribute("round1", "round1");

    // get back to JSP
    RequestDispatcher rd = getServletContext().getRequestDispatcher(redirect);
    rd.forward(request, response);

}

From source file:br.com.gamestore.Servlet.ChamadoServlet.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from  ww  w . j ava 2 s  .c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    /**
     * RECEBE A AO DO USU?RIO
     */
    String acao = request.getParameter("acao");
    Chamado chamado = new Chamado();
    ChamadoDao chamadoDao = new ChamadoDao();

    /**
     * SE A AO SEJA ABRIRCHAMADO, ELE RETORNAR? A TELA DE CHAMADO
     */
    if (acao.equals("abrirchamado")) {

        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

        /**
         * SE A AO SEJA LISTARCHAMADO, ELE RETORNA A LISTA DE CHAMADOS
         */
    } else if (acao.equals("listarchamado")) {

        try {
            List<Chamado> listachamado = chamadoDao.listarTodosChamados();
            request.setAttribute("listachamado", listachamado);

            RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/listachamado.jsp");
            dispatcher.forward(request, response);

        } catch (SQLException ex) {
            Logger.getLogger(ChamadoServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        /**
         * SE A AO SEJA ATENDER CHAMADO, OS DADOS DO CHAMADO SO LEVADO, PARA A TELA
         * ATENDER CHAMADO
        */
    } else if (acao.equals("atenderchamado")) {

        try {

            List<Chamado> listachamado;
            listachamado = chamadoDao.listarTodosChamados();
            request.setAttribute("listachamado", listachamado);
            RequestDispatcher dispatcher = request
                    .getRequestDispatcher("/WEB-INF/paginajsp/atenderchamado.jsp");
            dispatcher.forward(request, response);
        } catch (PersistenceException | SQLException ex) {
            Logger.getLogger(ChamadoServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        /**
         * SE A AO EXCLUIR, ELE EXCLUIR O CHAMADO 
         */
    } else if (acao.equals("excluir")) {
        String id = request.getParameter("id");
        chamado.setId(Integer.parseInt(id));
        if (id != null) {
            chamadoDao.excluir(chamado);

            response.sendRedirect("ChamadoServlet?acao=atenderchamado");
        }
        /**
         * SE A AO ATUALIZAR, ELE ATUALIZAR? AS INFORMAES DO CHAMADO
         */
    } else if (acao.equals("atualizarchamado")) {
        String id = request.getParameter("id");
        chamado = chamadoDao.buscarPorId(Integer.parseInt(id));
        request.setAttribute("chamado", chamado);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

        /**
         * SETA OS OBJETOS EM BRANCO NA TELA DE CHAMADO, ASSIM QUE O MESMO FOR ABERTO
         */
    } else if (acao.equals("cadastro")) {

        chamado.setEmail("");
        chamado.setTelefone("");
        chamado.setAssunto("");
        chamado.setComentario("");

        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/paginajsp/abrirchamado.jsp");
        dispatcher.forward(request, response);

    }
}

From source file:controller.uploadPergunta8.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  w  w  w.ja  va  2 s . c om*/
 *
 * @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 {

    String idLocal = (String) request.getParameter("idLocal");
    String idModelo = (String) request.getParameter("idModelo");
    String equacaoAjustada = (String) request.getParameter("equacaoAjustada");
    String idEquacaoAjustada = (String) request.getParameter("idEquacaoAjustada");

    String name = "";
    //process only if its multipart content
    if (ServletFileUpload.isMultipartContent(request)) {
        try {
            List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);

            for (FileItem item : multiparts) {
                if (!item.isFormField()) {
                    name = new File(item.getName()).getName();
                    //                        item.write( new File(UPLOAD_DIRECTORY + File.separator + name));
                    item.write(new File(AbsolutePath + File.separator + name));
                }
            }

            //File uploaded successfully
            request.setAttribute("message", "File Uploaded Successfully");
        } catch (Exception ex) {
            request.setAttribute("message", "File Upload Failed due to " + ex);
        }

    } else {
        request.setAttribute("message", "Sorry this Servlet only handles file upload request");
    }
    equacaoAjustada = equacaoAjustada.replace("+", "%2B");
    RequestDispatcher view = getServletContext().getRequestDispatcher(
            "/novoLocalPergunta8?id=" + idLocal + "&nomeArquivo=" + name + "&idModelo=" + idModelo
                    + "&equacaoAjustada=" + equacaoAjustada + "&idEquacaoAjustada=" + idEquacaoAjustada);
    view.forward(request, response);

    //        request.getRequestDispatcher("/novoLocalPergunta3?id="+idLocal+"&fupload=1&nomeArquivo="+name).forward(request, response);
    // request.getRequestDispatcher("/novoLocalPergunta4?id="+idLocal+"&nomeArquivo="+name).forward(request, response);

}

From source file:eu.eidas.node.service.IdPResponseServlet.java

/**
 * Executes the method {@link eu.eidas.node.auth.service.AUSERVICE#processIdpResponse} (of the ProxyService) and
 * then sets the internal variables used by the redirection JSP or the consent-value jsp, accordingly to {@link
 * EidasParameterKeys#NO_CONSENT_VALUE} or {@link EidasParameterKeys#CONSENT_VALUE} respectively.
 *
 * @param request/* w w w .  j  a v a 2  s.com*/
 * @param response
 * @return {@link EidasParameterKeys#CONSENT_VALUE} if the consent-value form is to be displayed, {@link
 * EidasParameterKeys#NO_CONSENT_VALUE} otherwise.
 * @see EidasParameterKeys#NO_CONSENT_VALUE
 * @see EidasParameterKeys#CONSENT_VALUE
 */

private void execute(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {

        RequestDispatcher dispatcher = getServletContext()
                .getRequestDispatcher(handleExecute(request, response));
        dispatcher.forward(request, response);
        HttpSession session = request.getSession(false);
        if (null != session
                && session.getAttribute(EidasParameterKeys.EIDAS_CONNECTOR_SESSION.toString()) == null) {
            session.invalidate();
        }
    } catch (ServletException e) {
        getLogger().info("ERROR : ServletException {}", e.getMessage());
        getLogger().debug("ERROR : ServletException {}", e);
        throw e;
    } catch (IOException e) {
        getLogger().info("IOException {}", e.getMessage());
        getLogger().debug("IOException {}", e);
        throw e;
    }

}

From source file:eu.semlibproject.annotationserver.servlets.OpenIDAuthentication.java

/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request/*  www  .j  a  v a2s.  c o  m*/
 * @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 {

    String userID = request.getParameter(SemlibConstants.OPENID_IDENTIFIER);
    String returned = request.getParameter(SemlibConstants.OPENID_RETURNED);

    String _returnPath = request.getParameter(SemlibConstants.OPENID_RETURN_PAGE);
    if (!StringUtils.isBlank(_returnPath)) {
        returnPath = _returnPath;
    }

    if ((StringUtils.isBlank(userID)) && returned == null) {
        request.setAttribute(SemlibConstants.OPENID_ATTRIBUTE_ERROR, "1");
        request.setAttribute(SemlibConstants.OPENID_ERROR_MESSAGE,
                SemlibConstants.OPENID_ERROR_MSG_LOGIN_PARAM_NOT_VALID);

        RequestDispatcher rd = getServletContext().getRequestDispatcher(returnPath);
        rd.forward(request, response);
        return;
    }

    if (returned != null) {
        processReturn(request, response);
    } else {
        authRequest(userID, request, response);
    }
}