Example usage for javax.servlet.http HttpServletResponse sendRedirect

List of usage examples for javax.servlet.http HttpServletResponse sendRedirect

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse sendRedirect.

Prototype

public void sendRedirect(String location) throws IOException;

Source Link

Document

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.

Usage

From source file:elw.web.StudentController.java

@RequestMapping(value = "Index", method = RequestMethod.GET)
public void do_Index(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    resp.sendRedirect("index");
}

From source file:elw.web.StudentController.java

@RequestMapping(value = "courses", method = RequestMethod.GET)
public void do_courses(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    resp.sendRedirect("index");
}

From source file:elw.web.StudentController.java

@RequestMapping(value = "course", method = RequestMethod.GET)
public void do_course(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    resp.sendRedirect("course");
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.SendRedirect.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache,no-store");

    String url = request.getParameter("URL");
    if (url != null && url.length() > 0) {
        response.sendRedirect(url);
    } else {/*from  w  w  w.  java 2s.co  m*/
        PrintWriter pout = response.getWriter();
        Page page = null;

        try {
            page = new Page();
            page.title("SendRedirect Servlet");

            page.add(new Heading(1, "SendRedirect Servlet"));

            page.add(new Heading(1, "Form to generate Dump content"));
            TableForm tf = new TableForm(response
                    .encodeURL(URI.addPaths(request.getContextPath(), request.getServletPath()) + "/action"));
            tf.method("GET");
            tf.addTextField("URL", "URL", 40, request.getContextPath() + "/dump");
            tf.addButton("Redirect", "Redirect");
            page.add(tf);
            page.write(pout);
            pout.close();
        } catch (Exception e) {
            log.warn(LogSupport.EXCEPTION, e);
        }
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.AddListenerController.java

@RequestMapping(value = "/addlistener", method = RequestMethod.GET)
public String createListener(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//w ww  .j  a  va2 s .  c  om
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to add new Table Listener");

    AddListener listenerAttribute = new AddListener();

    if (request.getParameter("tableName") != null) {
        listenerAttribute.setTableName(request.getParameter("tableName"));
    }

    if (request.getParameter("schemaName") != null) {
        listenerAttribute.setSchemaName(request.getParameter("schemaName"));
    }

    model.addAttribute("listenerAttribute", listenerAttribute);

    // This will resolve to /WEB-INF/jsp/addlistener.jsp
    return "addlistener";
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateGatewayReceiverController.java

@RequestMapping(value = "/creategatewayreceiver", method = RequestMethod.GET)
public String createGatewayReceiver(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from   w ww  .j a v a 2  s. c  o  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to create a new Gateway Receiver");

    model.addAttribute("gatewayReceiverAttribute", new NewGatewayReceiver());

    // This will resolve to /WEB-INF/jsp/create-gatewayreceiver.jsp
    return "create-gatewayreceiver";
}

From source file:org.chos.transaction.passport.controller.WechatPassportController.java

@RequestMapping(value = "/wechat/login")
public void login(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String code = request.getParameter("code");
    String state = request.getParameter("state");
    OAuthSession session = sessionService.getSession(state);
    if (session == null) {
        response.sendRedirect("http://chos2009.eicp.net/login.shtml");
    }/*from   w w w .  ja v  a2  s. co  m*/
    if (state == null) {
        response.sendRedirect("http://chos2009.eicp.net/login.shtml");
    }
    if (!state.equals(session.getState())) {
        response.sendRedirect("http://chos2009.eicp.net/login.shtml");
    }
    Map<String, String> param = new HashMap<String, String>();
    param.put("appid", "wxd5c717bf0a6db8a5");
    param.put("secret", "ebb68eb5937479818ac829417bf31919");
    param.put("grant_type", "authorization_code");
    param.put("code", code);
    HttpTemplate template = new HttpTemplate();
    String resp = null;
    try {
        resp = template.post("https://api.weixin.qq.com/sns/oauth2/access_token", param);
    } catch (HttpException e) {
        response.sendRedirect("http://chos2009.eicp.net/login.shtml");
    }
    Map<String, Object> paramMap = parseParam(resp);
    String ak = (String) paramMap.get("access_token");
    String openId = (String) paramMap.get("openid");

    param = new HashMap<String, String>();
    param.put("access_token", ak);
    param.put("openid", openId);
    param.put("lang", "zh_CN");
    try {
        resp = template.post("https://api.weixin.qq.com/sns/userinfo", param);
    } catch (HttpException e) {
        response.sendRedirect("http://chos2009.eicp.net/login.shtml");
    }
    JSONObject json = JSONObject.fromObject(resp);
    String unionId = json.getString("unionid");
    openId = json.getString("openid");
    String nickname = json.getString("nickname");

    User user = userService.create(unionId + "@wechat", null, "13120984792", "13120984792@qq.com", true,
            request, response);
    response.sendRedirect("http://chos2009.eicp.net/mindex.htm");
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateTypeController.java

@RequestMapping(value = "/createtype", method = RequestMethod.POST)
public String createTypeAction(@ModelAttribute("typeAttribute") Type typeAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*www .  j  ava  2  s . c om*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create UDT (Type)");

    String schema = typeAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New Type schema name = " + schema);
    logger.debug("New Type name = " + typeAttribute.getTypeName());

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createType = new StringBuffer();

        createType.append("CREATE TYPE " + schema + "." + typeAttribute.getTypeName() + " \n");
        createType.append("EXTERNAL NAME '" + typeAttribute.getJavaClassName() + "' \n");
        createType.append("LANGUAGE JAVA \n");

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating UDT Type as -> " + createType.toString());

            result = GemFireXDWebDAOUtil.runCommand(createType.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create UDT (Type) SQL as follows as -> " + createType.toString());
            model.addAttribute("sql", createType.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, typeAttribute.getTypeName()));

            ServletOutputStream out = response.getOutputStream();
            out.println(createType.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-type.jsp
    return "create-type";
}

From source file:nl.surfnet.coin.selfservice.filter.ApiOAuthFilter.java

private void initiateOauthAuthorization(HttpServletRequest httpRequest, HttpServletResponse response,
        HttpSession session) throws IOException {
    final String currentRequestUrl = getCurrentRequestUrl(httpRequest);
    session.setAttribute(ORIGINAL_REQUEST_URL, currentRequestUrl);
    response.sendRedirect(apiClient.getAuthorizationUrl());
}

From source file:pivotal.au.se.gemfirexdweb.controller.AddLoaderController.java

@RequestMapping(value = "/addloader", method = RequestMethod.POST)
public String createLoaderAction(@ModelAttribute("loaderAttribute") AddLoader loaderAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*ww w . j a va 2s  .co  m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for Table Loader");

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer addLoader = new StringBuffer();

        addLoader.append("CALL SYS.ATTACH_LOADER ('" + loaderAttribute.getSchemaName() + "', \n");
        addLoader.append("'" + loaderAttribute.getTableName() + "', \n");
        addLoader.append("'" + loaderAttribute.getFunctionName() + "', \n");

        if (!checkIfParameterEmpty(request, "initInfoString")) {
            addLoader.append("'" + loaderAttribute.getInitInfoString() + "') \n");
        } else {
            addLoader.append("NULL) \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating Table Loader as -> " + addLoader.toString());

            result = GemFireXDWebDAOUtil.runStoredCommand(addLoader.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Table Loader SQL as follows as -> " + addLoader.toString());
            model.addAttribute("sql", addLoader.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition", "attachment; filename="
                    + String.format(FILENAME, loaderAttribute.getTableName() + "-Loader"));

            ServletOutputStream out = response.getOutputStream();
            out.println(addLoader.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/addloader.jsp
    return "addloader";
}