Example usage for javax.servlet.http HttpServletResponse getWriter

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

Introduction

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

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:com.gae.LoginServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String thisURL = req.getRequestURI();
    resp.setContentType("text/html");
    UserService userService = UserServiceFactory.getUserService();
    PrintWriter pw = resp.getWriter();
    if (req.getUserPrincipal() == null) {
        pw.println("<a href=\"" + userService.createLoginURL(thisURL) + "\">Login</a>");
    } else {/*from   ww w.  j  a  va  2 s.co m*/
        User user = userService.getCurrentUser();
        pw.println("<a href=\"" + userService.createLogoutURL(thisURL) + "\">Logout</a><br/>");
        pw.println("name = " + req.getUserPrincipal().getName() + "<br/>");
        pw.println("isAdmin = " + userService.isUserAdmin() + "<br/>");
        pw.println("domain = " + user.getAuthDomain() + "<br/>");
        pw.println("email = " + user.getEmail() + "<br/>");
        pw.println("nickname = " + user.getNickname() + "<br/>");
    }
}

From source file:communicator.doSignIn.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//  w w  w . j a  va 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 {
    //processRequest(request, response);
    response.getWriter().println(Constants.getRequestNotSupported());
}

From source file:com.commercehub.dropwizard.BuildInfoServlet.java

private void writeAllHtml(HttpServletResponse response) throws IOException {
    response.setContentType(MediaType.TEXT_HTML);
    PrintWriter writer = response.getWriter();

    writer.println("<html>");
    writer.println("  <body>");
    writer.println("    <h1>Info</h1>");
    writer.println("    <ul>");
    for (String key : manifestAttributes.stringPropertyNames()) {
        writer.format("      <li>%s: %s</li>", key, manifestAttributes.get(key));
    }/*  w w  w.j  a v a2 s.  co  m*/
    writer.println("    </ul>");
    writer.println("  </body>");
    writer.println("</html>");
}

From source file:redeemCoupon.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  ww. ja v  a  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 {
    response.setContentType("application/json;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        String deviceId = request.getParameter("deviceId");
        String couponId = request.getParameter("couponId");
        String tranToken = request.getParameter("tranToken");

        String url = "https://tgl.standardchartered.com/bridgeheadi18n/mcoupon/redeem?deviceId=" + deviceId
                + "&couponId=" + couponId + "&TT=" + tranToken;
        HttpClient client = new DefaultHttpClient();
        HttpGet req = new HttpGet(url);
        HttpResponse res = client.execute(req);
        BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
        String line = "";
        String total = "";
        while ((line = rd.readLine()) != null) {
            total += line;
        }

        total = total.substring(0, total.length());
        out.println(total);
    }
}

From source file:com.seer.datacruncher.profiler.spring.DbInfoController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {//from   w  w w . j  a  v  a2 s.  c  om
        PrintWriter out = response.getWriter();
        DbInfoBL dbBL = new DbInfoBL();
        ObjectMapper mapper = new ObjectMapper();
        String json = "";
        String text = CommonUtil.notNullValue(request.getParameter("text"));
        if (CommonUtil.notNullValue(request.getParameter("type")).equals("geninfo")) {
            json = mapper.writeValueAsString(dbBL.getGeneralInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("supinfo")) {
            json = mapper.writeValueAsString(dbBL.getSupportInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("limitinfo")) {
            json = mapper.writeValueAsString(dbBL.getLimitationInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("funcinfo")) {
            json = mapper.writeValueAsString(dbBL.getFunctionInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("cataloginfo")) {
            json = mapper.writeValueAsString(dbBL.getCatalogInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("standardsqlinfo")) {
            json = mapper.writeValueAsString(dbBL.getStandardSQLInfo());
        }

        else if (CommonUtil.notNullValue(request.getParameter("type")).equals("tableprivilegeinfo")) {
            json = mapper.writeValueAsString(dbBL.getTablePrivilege(text));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("columnprivilegeinfo")) {
            json = mapper.writeValueAsString(dbBL.getColumnPrivilege(text));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("tablemetadatainfo")) {
            json = mapper.writeValueAsString(dbBL.getTableMetaData(text));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("procedureinfo")) {
            json = mapper.writeValueAsString(dbBL.getProcedureInfo());
        }

        else if (CommonUtil.notNullValue(request.getParameter("type")).equals("parameterinfo")) {
            json = mapper.writeValueAsString(dbBL.getParameterInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("usersqlinfo")) {
            json = mapper.writeValueAsString(dbBL.getUserSQLInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("schemainfo")) {
            json = mapper.writeValueAsString(dbBL.getSchemaInfo());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("indexinfo")) {
            json = mapper.writeValueAsString(dbBL.IndexQuery(null));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("dbmetadatainfo")) {
            json = mapper.writeValueAsString(dbBL.DbMetaDataQuery());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("alltableprivinfo")) {
            json = mapper.writeValueAsString(dbBL.AllTablesPrivilegeQuery());
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("datainfo")) {
            json = mapper.writeValueAsString(dbBL.DataQuery(null));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("tabledatainfo")) {
            json = mapper.writeValueAsString(dbBL.DataQuery(text));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("tableindexinfo")) {
            json = mapper.writeValueAsString(dbBL.IndexQuery(text));
        } else if (CommonUtil.notNullValue(request.getParameter("type")).equals("tablemodelinfo")) {
            // json = mapper.writeValueAsString(dbBL.IndexQuery(text));
            Hashtable data = dbBL.tableModelInfo(CommonUtil.notNullValue(request.getParameter("subType")));
            request.setAttribute("relationData", data);
            if (CommonUtil.notNullValue(request.getParameter("subType")).equals("noFK")) {
                return new ModelAndView("jsp/profiler/tableWithNoFK.jsp");
            } else if (CommonUtil.notNullValue(request.getParameter("subType")).equals("noPK")) {
                return new ModelAndView("jsp/profiler/tableWithNoPK.jsp");
            }
        }
        out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.motechproject.mobile.web.IncomingMessageServlet.java

/** 
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * @param request servlet request/* w  w  w .  ja va2s .  com*/
 * @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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        ApplicationContext appContext = (ApplicationContext) request.getSession().getServletContext()
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

        WebManager webManager = (WebManager) appContext.getBean("webManagerBean");
        IncomingMessageRequestWorker imrWorker = webManager.createIMRWorker();

        String responseString = imrWorker.doRequest(request.getParameterMap());

        out.print(responseString.replaceAll("\n", "<br />"));
    } finally {
        out.close();
    }
}

From source file:controller.deleteGame.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w  w  . j a va2s  .com*/
 *
 * @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 {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {

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

        Check c = new Check();

        c.setCode(Code);

        int i = c.deleteGame();

        if (i > 0) {
            RequestDispatcher rd = request.getRequestDispatcher("viewGames.jsp");
            request.setAttribute("return", "Data deleted successfully.");
            rd.forward(request, response);
        } else {
            RequestDispatcher rd = request.getRequestDispatcher("deleteGame.jsp");
            request.setAttribute("return", "Unable to delete data.");
            rd.forward(request, response);
        }
    }
}

From source file:de.mpg.escidoc.services.syndication.presentation.RestServlet.java

/**
 * Take care on an incoming exception.//from w w  w  .  j a v a2s  . c o  m
 * 
 * @param e
 *            exception
 * @param resp
 *            response stream
 * @throws IOException 
 * @throws Exception
 *             if the handling went wrong on any reason
 */
private void handleException(final Exception e, final HttpServletResponse resp) throws IOException {
    logger.error(e.getMessage(), e);

    PrintWriter pw;
    pw = resp.getWriter();
    pw.print("Error: ");
    e.printStackTrace(pw);
    pw.close();
}

From source file:edu.lafayette.metadb.web.authentication.GetPermission.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *//*from   ww  w .jav a 2 s  .  c o m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    Permission permission = null;
    HttpSession session = request.getSession(false);
    JSONObject output = new JSONObject();

    try {
        if (session.getAttribute(Global.SESSION_BYPASS) != null) {
            output.put("admin", true);
            return;
        }
        String projectName = (String) session.getAttribute(Global.SESSION_PROJECT);
        String username = (String) session.getAttribute(Global.SESSION_USERNAME);

        if (UserManDAO.getUserData(username).getType().equalsIgnoreCase("admin"))
            output.put("admin", true);
        else {
            output.put("admin", false);
            permission = PermissionManDAO.getUserPermission(username, projectName);
            if (permission != null) {
                output.put("administrative", permission.getAdmin_md());
                output.put("descriptive", permission.getDesc_md());
                output.put("data", permission.getData());
                output.put("table_edit", permission.getTable_edit());
                output.put("controlled_vocab", permission.getControlled_vocab());
            } else {
                output.put("administrative", "none");
                output.put("descriptive", "none");
                output.put("data", "none");
                output.put("table_edit", "none");
                output.put("controlled_vocab", "none");
            }
        }
        out.print(output);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    response.setContentType("application/x-json");
    out.flush();
}