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: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 w w  .j  a va  2s  . c o  m*/

        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:edu.cornell.mannlib.vitro.webapp.controller.edit.Properties2PropertiesRetryController.java

public void doGet(HttpServletRequest req, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) {
        return;/*w  ww . jav a2s.  c  o m*/
    }

    VitroRequest request = new VitroRequest(req);

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    String action = null;
    if (epo.getAction() == null) {
        action = "insert";
        epo.setAction("insert");
    } else {
        action = epo.getAction();
    }

    ObjectPropertyDao opDao = request.getUnfilteredWebappDaoFactory().getObjectPropertyDao();
    DataPropertyDao dpDao = request.getUnfilteredWebappDaoFactory().getDataPropertyDao();
    epo.setDataAccessObject(opDao);

    List propList = ("data".equals(request.getParameter("propertyType"))) ? dpDao.getAllDataProperties()
            : opDao.getAllObjectProperties();

    sortForPickList(propList, request);

    String superpropertyURIstr = request.getParameter("SuperpropertyURI");
    String subpropertyURIstr = request.getParameter("SubpropertyURI");

    HashMap<String, Option> hashMap = new HashMap<String, Option>();
    List<Option> optionList = FormUtils.makeOptionListFromBeans(propList, "URI", "PickListName",
            superpropertyURIstr, null);
    List<Option> superPropertyOptions = getSortedList(hashMap, optionList, request);
    optionList = FormUtils.makeOptionListFromBeans(propList, "URI", "PickListName", subpropertyURIstr, null);
    List<Option> subPropertyOptions = getSortedList(hashMap, optionList, request);

    HashMap hash = new HashMap();
    hash.put("SuperpropertyURI", superPropertyOptions);
    hash.put("SubpropertyURI", subPropertyOptions);

    FormObject foo = new FormObject();
    foo.setOptionLists(hash);

    epo.setFormObject(foo);

    request.setAttribute("operation", "add");

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    String modeStr = request.getParameter("opMode");
    if (modeStr != null && (modeStr.equals("superproperty") || modeStr.equals("subproperty")
            || modeStr.equals("equivalentProperty"))) {
        request.setAttribute("editAction", "props2PropsOp");
        request.setAttribute("formJsp", "/templates/edit/specific/properties2properties_retry.jsp");
        request.setAttribute("title", (modeStr.equals("superproperty") ? "Add Superproperty"
                : modeStr.equals("equivalentProperty") ? "Add Equivalent Property" : "Add Subproperty"));
    }
    request.setAttribute("opMode", modeStr);

    request.setAttribute("_action", action);
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error(this.getClass().getName() + " could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}

From source file:at.gv.egovernment.moa.id.proxy.servlet.ProxyServlet.java

/**
 * Handles an error. <br>/*from   ww  w  .j  a va  2 s  .  c  o  m*/
 * <ul>
 * <li>Logs the error</li>
 * <li>Places error message and exception thrown into the request 
 *        as request attributes (to be used by <code>"/errorpage-proxy.jsp"</code>)</li>
 * <li>Sets HTTP status 500 (internal server error)</li>
 * </ul>
 * 
 * @param errorMessage error message
 * @param exceptionThrown exception thrown
 * @param req servlet request
 * @param resp servlet response
 */
protected void handleError(String errorMessage, Throwable exceptionThrown, HttpServletRequest req,
        HttpServletResponse resp) {

    if (null != errorMessage) {
        Logger.error(errorMessage);
        req.setAttribute("ErrorMessage", errorMessage);
    }

    if (null != exceptionThrown) {
        if (null == errorMessage)
            errorMessage = exceptionThrown.getMessage();
        Logger.error(errorMessage, exceptionThrown);
        //req.setAttribute("ExceptionThrown", exceptionThrown);
    }

    if (Logger.isDebugEnabled()) {
        req.setAttribute("LogLevel", "debug");
    }

    //forward this to errorpage-proxy.jsp where the HTML error page is generated
    ServletContext context = getServletContext();
    RequestDispatcher dispatcher = context.getRequestDispatcher("/errorpage-proxy.jsp");
    try {
        dispatcher.forward(req, resp);
    } catch (ServletException e) {
        Logger.error(e);
    } catch (IOException e) {
        Logger.error(e);
    }

}

From source file:com.alfaariss.oa.sso.web.profile.user.UserProfile.java

private void processAuthN(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        ISession session) throws OAException {
    try {/*ww w.  j av a2 s . c om*/
        if (session != null) {//user should not be here, show default page instead
            processDefault(servletRequest, servletResponse, session);
        } else {
            String sRequestURL = _sRedirectURL;
            if (sRequestURL == null) {
                sRequestURL = servletRequest.getRequestURL().toString();
                if (sRequestURL.endsWith("/"))
                    sRequestURL = sRequestURL.substring(0, sRequestURL.length() - 1);

                if (sRequestURL.endsWith(PROFILE_ID + "/" + TARGET_AUTHN))
                    sRequestURL = sRequestURL.substring(0, sRequestURL.length() - TARGET_AUTHN.length());
            }

            session = _sessionFactory.createSession(_sUserPageRequestorId);
            session.persist();//resist for creating the session id

            StringBuilder sbProfileURL = new StringBuilder(sRequestURL);
            if (!sRequestURL.endsWith("/"))
                sbProfileURL.append("/");
            sbProfileURL.append("?");
            sbProfileURL.append(ISession.ID_NAME);
            sbProfileURL.append("=");
            sbProfileURL.append(session.getId());
            session.setProfileURL(sbProfileURL.toString());

            //don't have to persist the session, because the target of the foward is the /sso

            servletRequest.setAttribute(ISession.ID_NAME, session);

            _logger.debug("Starting authentication");

            String sServletPath = servletRequest.getServletPath();

            RequestDispatcher oDispatcher = servletRequest.getRequestDispatcher(sServletPath);
            if (oDispatcher == null) {
                _logger.warn("There is no requestor dispatcher supported with name: " + sServletPath);
                throw new OAException(SystemErrors.ERROR_INTERNAL);
            }

            oDispatcher.forward(servletRequest, servletResponse);
        }
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during authentication", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:atd.backend.Login.java

/**
 * Vangt het POST request van de login.jsp en controlleerd deze met de
 * database/* w  w  w. j av  a2s. c  om*/
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String username = req.getParameter("username").toLowerCase();

    try {
        Class.forName("org.apache.commons.codec.digest.DigestUtils");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String pass = org.apache.commons.codec.digest.DigestUtils.sha256Hex(req.getParameter("password"));
    RequestDispatcher rd = null;

    if (UsersDAO.authUser(username, pass)
            || (username.equals(adminUser)) && req.getParameter("password").equals(adminPwd)) {
        // Controlleer of het filter een redirect gezet heeft
        if (req.getAttribute("redirect") == null || req.getAttribute("redirect").equals("")) {
            rd = req.getRequestDispatcher("/index.jsp");
        } else {
            rd = req.getRequestDispatcher((String) req.getAttribute("redirect"));
            req.removeAttribute("redirect");
        }

        req.getSession().setAttribute("username", UsersDAO.searchUser(username));
        resp.addCookie(new Cookie("username", username));
        java.util.Date dt = new java.util.Date();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(dt);
        LogDAO.setLog(req.getRemoteAddr(), currentTime, UsersDAO.searchUser(username), null);
        rd.forward(req, resp);
    } else if (KlantenDAO.authKlant(username, pass)) {
        if (req.getAttribute("redirect") == null || req.getAttribute("redirect").equals("")) {
            rd = req.getRequestDispatcher("/index.jsp");
        } else {
            rd = req.getRequestDispatcher((String) req.getAttribute("redirect"));
            req.removeAttribute("redirect");
        }
        req.getSession().setAttribute("username", KlantenDAO.searchKlant(username));
        System.out.println("klant setten");

        resp.addCookie(new Cookie("username", username));

        java.util.Date dt = new java.util.Date();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(dt);

        LogDAO.setLog(req.getRemoteAddr(), currentTime, null, KlantenDAO.searchKlant(username));
        rd.forward(req, resp);
    } else {
        rd = req.getRequestDispatcher("/login/login.jsp");
        req.setAttribute("error",
                "<div class=\"alert alert-danger\" role=\"alert\"> <span class=\"sr-only\">Error:</span> ongeldige inlog gegevens </div>");
        rd.forward(req, resp);
    }
}

From source file:com.alfaariss.oa.sso.web.profile.user.UserProfile.java

private void processLogout(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        ISession session) throws OAException {
    try {//from   w w w.  j  a v a 2 s  .c o m
        String sTGTCookie = _cookieTool.getCookieValue(WebSSOServlet.TGT_COOKIE_NAME, servletRequest);
        if (sTGTCookie == null) {
            _logger.debug("No TGT cookie found, user already loggedout");

            if (session != null) {
                session.expire();
                session.persist();
            }

            processDefault(servletRequest, servletResponse, null);
            return;
        }

        String sServletPath = servletRequest.getServletPath();

        if (session == null) {
            String sRequestURL = _sRedirectURL;
            if (sRequestURL == null) {
                sRequestURL = servletRequest.getRequestURL().toString();
                if (sRequestURL.endsWith("/"))
                    sRequestURL = sRequestURL.substring(0, sRequestURL.length() - 1);

                if (sRequestURL.endsWith(PROFILE_ID + "/" + TARGET_LOGOUT))
                    sRequestURL = sRequestURL.substring(0, sRequestURL.length() - TARGET_LOGOUT.length());
            }

            session = _sessionFactory.createSession(_sUserPageRequestorId);
            session.persist();//resist for creating the session id

            StringBuilder sbProfileURL = new StringBuilder(sRequestURL);
            if (!sRequestURL.endsWith("/"))
                sbProfileURL.append("/");
            sbProfileURL.append("?");
            sbProfileURL.append(ISession.ID_NAME);
            sbProfileURL.append("=");
            sbProfileURL.append(session.getId());
            session.setProfileURL(sbProfileURL.toString());
        }

        _logger.debug("Starting logout");

        session.persist();//update session; also to increase lifetime

        servletRequest.setAttribute(ISession.ID_NAME, session);

        StringBuilder sbForward = new StringBuilder(sServletPath);
        if (!sServletPath.endsWith("/"))
            sbForward.append("/");
        sbForward.append(LogoutProfile.PROFILE_ID);

        RequestDispatcher oDispatcher = servletRequest.getRequestDispatcher(sbForward.toString());
        if (oDispatcher == null) {
            _logger.warn("There is no requestor dispatcher supported with name: " + sbForward.toString());
            throw new OAException(SystemErrors.ERROR_INTERNAL);
        }

        oDispatcher.forward(servletRequest, servletResponse);
    } catch (OAException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during logout", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:atd.backend.Register.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    RequestDispatcher rd = null;
    System.out.println(req.getParameter("checkbox"));
    if (req.getParameter("checkbox") != null) {
        String username = req.getParameter("username").toLowerCase();
        String realName = req.getParameter("realname");

        try {/* w  w  w .ja  v a  2 s .c o m*/
            Class.forName("org.apache.commons.codec.digest.DigestUtils");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String wachtwoord = org.apache.commons.codec.digest.DigestUtils.sha256Hex(req.getParameter("password"));
        if (UsersDAO.searchUser(username) != null) {
            req.setAttribute("errorReg",
                    "<div class=\"alert alert-danger\" role=\"alert\"> <span class=\"sr-only\">Error:</span> Username is bezet</div>");
            rd = req.getRequestDispatcher("register/register.jsp");
            rd.forward(req, resp);
            return;
        }
        if (username.equals("") || realName.equals("") || wachtwoord.equals("")) {
            req.setAttribute("errorReg",
                    "<div class=\"alert alert-danger\" role=\"alert\"> <span class=\"sr-only\">Error:</span> Er is een veld leeg</div>");
            rd = req.getRequestDispatcher("register/register.jsp");
            rd.forward(req, resp);
            return;
        }

        // Hier moet nog een uurloon veld komen
        UsersDAO.setUser(new User(0, realName, username, Privilege.MONTEUR, 10.00), wachtwoord);
        req.setAttribute("error",
                "<div class=\"alert alert-success\" role=\"alert\"> <span class=\"sr-only\">Info:</span> nieuwe gebruiker is aangemaakt </div>");
        rd = req.getRequestDispatcher("login/login.jsp");
        rd.forward(req, resp);
    } else {
        String username = req.getParameter("username").toLowerCase();
        String realName = req.getParameter("realname");

        try {
            Class.forName("org.apache.commons.codec.digest.DigestUtils");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String wachtwoord = org.apache.commons.codec.digest.DigestUtils.sha256Hex(req.getParameter("password"));
        String postcode = req.getParameter("postcode");
        String email = req.getParameter("email");

        String kenteken = req.getParameter("kenteken");
        String merk = req.getParameter("merk");
        String type = req.getParameter("type");

        if (KlantenDAO.searchKlant(username) != null) {
            req.setAttribute("errorReg",
                    "<div class=\"alert alert-danger\" role=\"alert\"> <span class=\"sr-only\">Error:</span> Username bestaat al</div>");
            rd = req.getRequestDispatcher("register/register.jsp");
            rd.forward(req, resp);
            return;
        }

        if (username.equals("") || realName.equals("") || wachtwoord.equals("") || postcode.equals("")
                || email.equals("") || kenteken.equals("") || merk.equals("") || type.equals("")) {
            req.setAttribute("errorReg",
                    "<div class=\"alert alert-danger\" role=\"alert\"> <span class=\"sr-only\">Error:</span> Er is een veld leeg</div>");
            rd = req.getRequestDispatcher("register/register.jsp");
            rd.forward(req, resp);
            return;
        }

        AutoDAO.setAuto(new Auto(0, kenteken, merk, type));
        Klant k = new Klant(0, realName, username, postcode, email, AutoDAO.searchAuto(kenteken),
                Privilege.KLANT);
        KlantenDAO.setKlant(k, wachtwoord);
        sendRegMail(k);
        req.setAttribute("error",
                "<div class=\"alert alert-success\" role=\"alert\"> <span class=\"sr-only\">Info:</span> Gebruiker "
                        + k.getUsername() + " is aangemaakt </div>");
        rd = req.getRequestDispatcher("login/login.jsp");
        rd.forward(req, resp);
    }
}

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

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *///from  w  ww.java 2s.c om
@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:org.overlord.sramp.server.servlets.MavenRepositoryServlet.java

/**
 * List items response.//w ww. jav  a 2 s  . com
 *
 * @param req
 *            the req
 * @param resp
 *            the resp
 * @param url
 *            the url
 * @throws ServletException
 *             the servlet exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private void listItemsResponse(HttpServletRequest req, HttpServletResponse resp, String url)
        throws ServletException, IOException {
    if (!url.endsWith("/")) { //$NON-NLS-1$
        url = url + "/"; //$NON-NLS-1$
    }
    try {
        // Gets all the items from the maven url
        Set<String> items = service.getItems(url);

        // If there are items or the request is the root maven folder
        if ((items != null && items.size() > 0) || (url.equals("/") || url.equals(""))) { //$NON-NLS-1$ //$NON-NLS-2$
            // Dispatch the request to the JSP that would display the items
            RequestDispatcher dispatcher = req.getRequestDispatcher(JSP_LOCATION_LIST_DIR);
            if (StringUtils.isNotBlank(url) && !url.equals("/")) { //$NON-NLS-1$
                String[] urlTokens = url.split("/"); //$NON-NLS-1$
                String parentPath = ""; //$NON-NLS-1$
                if (urlTokens.length > 1) {
                    for (int i = 0; i < urlTokens.length - 1; i++) {
                        parentPath += urlTokens[i] + "/"; //$NON-NLS-1$
                    }
                }
                parentPath = "/" + parentPath; //$NON-NLS-1$
                req.setAttribute("parentPath", parentPath); //$NON-NLS-1$
            } else {
                url = ""; //$NON-NLS-1$
            }
            req.setAttribute("relativePath", url); //$NON-NLS-1$
            req.setAttribute("items", items); //$NON-NLS-1$
            dispatcher.forward(req, resp);
        } else {
            resp.setStatus(HttpStatus.SC_NOT_FOUND);
        }
    } catch (MavenRepositoryException e) {
        resp.sendError(HttpStatus.SC_NOT_FOUND, e.getMessage());
    }
}

From source file:Service.java

/**
 * When the servlet receives a POST request.
 *///w  w w . j a v  a 2  s.c  o m
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String forward = ""; // Which jsp page is going to be return.
    String eurosentiment = ""; // This is the analysis response.
    // Auxiliar variables.
    HttpEntity entity = null;
    HttpSession session = request.getSession();
    RequestDispatcher view;
    // Get a map of the request parameters
    Map parameters = request.getParameterMap();
    if (parameters.containsKey("input")) { // If the request contains a parameter named input
        if (parameters.containsKey("intype") && parameters.containsKey("informat")
                && parameters.containsKey("outformat")) { // If the request contains a parameter named intype, informat and outformat.
            if (!request.getParameter("intype").equalsIgnoreCase("direct")) { // If intype is not direct.
                // The response contains only the following message.
                forward = RESPONSE_JSP;
                eurosentiment = "intype should be direct";
                session.setAttribute("eurosentiment", eurosentiment);
                view = request.getRequestDispatcher(forward);
                view.forward(request, response);
                return;
            }
            if (!request.getParameter("informat").equalsIgnoreCase("text")) { // If informat is not text
                // The response contains only the following message.
                forward = RESPONSE_JSP;
                eurosentiment = "informat should be text";
                session.setAttribute("eurosentiment", eurosentiment);
                view = request.getRequestDispatcher(forward);
                view.forward(request, response);
                return;
            }
            if (!request.getParameter("outformat").equalsIgnoreCase("json-ld")) { // If outformat is not json-ld
                // The response contains only the following message.
                forward = RESPONSE_JSP;
                eurosentiment = "outformat should be json-ld";
                session.setAttribute("eurosentiment", eurosentiment);
                view = request.getRequestDispatcher(forward);
                view.forward(request, response);
                return;
            }
            // If there is input, intype = direct, informat = text and outformat = json-ld,
            forward = RESPONSE_JSP; // response.jsp
            String textToAnalize = request.getParameter("input"); // Text to be analyzed.
            try {
                if (parameters.containsKey("algo")) { // If the request contains a parameter named algo (algorithm)
                    if (request.getParameter("algo").equalsIgnoreCase("spFinancial")) { // If algo = spFinancial
                        entity = callSAGA(textToAnalize, "spFinancial"); // The corresponding GATE module is called and a MARL entity is generated.
                    } else if (request.getParameter("algo").equalsIgnoreCase("emoticon")) { // If algo = Emoticon
                        entity = callSAGA(textToAnalize, "emoticon"); // The corresponding GATE module is called and a MARL entity is generated.
                    } else if (request.getParameter("algo").equalsIgnoreCase("spFinancialEmoticon")) { // If algo = spFinancialEmoticon
                        entity = callSAGA(textToAnalize, "spFinancialEmoticon"); // The corresponding GATE module is called and a MARL entity is generated.
                    } else { // If the request contains a non-valid algorithm.
                        forward = RESPONSE_JSP;
                        eurosentiment = "Introduce a valid algorithm";
                        session.setAttribute("eurosentiment", eurosentiment);
                        view = request.getRequestDispatcher(forward);
                        view.forward(request, response);
                        return;
                    }
                }
                // If a GATE module has been called and a MARL entity has been generated.
                if (entity != null) {
                    // The MARL entity is processed to be added to the response.jsp
                    InputStream instream = entity.getContent();
                    try {
                        // The entity is parsed into a StringBuffer.
                        BufferedReader in = new BufferedReader(new InputStreamReader(instream));
                        String inputLine;
                        StringBuffer marl = new StringBuffer();
                        while ((inputLine = in.readLine()) != null) {
                            marl.append(inputLine);
                            marl.append("\n");
                        }
                        in.close();
                        // The variable eurosentiment (String) is setted with the MARL response.
                        eurosentiment = marl.toString();
                        session.setAttribute("eurosentiment", eurosentiment);
                    } finally {
                        instream.close();
                    }
                }
            } catch (Exception e) {
                System.err.println(e);
            }
        } else { // If there is no intype, informat or outformat specified.
            forward = RESPONSE_JSP;
            eurosentiment = "There is no intype, informat or outformat specified";
            session.setAttribute("eurosentiment", eurosentiment);
        }
    } else { // If there is no input.
        forward = RESPONSE_JSP;
        eurosentiment = "There is no input";
        session.setAttribute("eurosentiment", eurosentiment);
    }
    view = request.getRequestDispatcher(forward);
    view.forward(request, response);

}