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.aurel.track.dbase.ReadyTesterServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    prepareResponse(resp);// w w  w.  j  av a 2s. c om
    PrintWriter out = resp.getWriter();
    Enumeration<Locale> locales = req.getLocales();
    execute(out, locales);
}

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

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

    PrintWriter out = response.getWriter();
    String action = CommonUtil.notNullValue(request.getParameter("action"));

    if (action.equals("validateCondition") || action.equals("applyCondition")) {
        String table = CommonUtil.notNullValue(request.getParameter("table"));
        String columnNames = CommonUtil.notNullValue(request.getParameter("columnNames"));
        String columnType = CommonUtil.notNullValue(request.getParameter("columnTypes"));
        String condition = CommonUtil.notNullValue(request.getParameter("condition"));
        String conditionValue = CommonUtil.notNullValue(request.getParameter("conditionValue"));
        String conditionType = CommonUtil.notNullValue(request.getParameter("conditionType"));
        String indexValue = CommonUtil.notNullValue(request.getParameter("index"));
        MiscBL mbl = new MiscBL(1, table, (Integer.parseInt(indexValue) - 1));

        mbl.initMiscBL(columnNames, conditionType, conditionValue, columnType, condition);

        if (action.equals("validateCondition")) {
            String status = mbl.validateCondtion();
            if (status != null) {
                out.print("{success: true, count: \"" + status + "\" , conditionQuery:\"" + mbl.cond + "\"}");
            } else {
                out.println("{\"success\": false}");
            }/* w ww .  j a v  a 2s .  c  om*/
        } else {
            @SuppressWarnings("unchecked")
            Hashtable<String, String> dbParams = (Hashtable<String, String>) request.getSession(true)
                    .getAttribute("dbConnectionData");
            if (dbParams != null) {
                request.setAttribute("serverName", CommonUtil.notNullValue(dbParams.get("Database_DSN")));
            }
            String selectedValue = CommonUtil.notNullValue(request.getParameter("table"));
            request.setAttribute("selectedValue", selectedValue);
            TableGridDTO tgDTO = mbl.applyCondition();
            GridUtil gridUtil = new GridUtil();
            gridUtil.generateGridData(tgDTO, false, null);
            request.setAttribute("gridColumns", gridUtil.getColumnNames());
            request.setAttribute("gridFields", gridUtil.getFieldNames());
            request.setAttribute("gridData", gridUtil.getData());

            request.setAttribute("rowCount", tgDTO.getRowValues().size());

            return new ModelAndView("jsp/profiler/info.jsp");
        }
    }
    return null;

}

From source file:CounterRewrite.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    int count = 1;
    Integer i = (Integer) session.getAttribute(COUNTER_KEY);
    if (i != null) {
        count = i.intValue() + 1;// w w w. j av a2  s .  co m
    }
    session.setAttribute(COUNTER_KEY, new Integer(count));
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Session Counter</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("Your session ID is <b>" + session.getId());
    out.println("</b> and you have hit this page <b>" + count + "</b> time(s) during this browser session");

    String url = req.getRequestURI();
    out.println("<form method=GET action=\"" + resp.encodeURL(url) + "\">");
    out.println("<input type=submit " + "value=\"Hit page again\">");
    out.println("</form>");
    out.println("</body>");
    out.println("</html>");
    out.flush();
}

From source file:de.knurt.fam.core.model.config.CronjobActionController.java

private ModelAndView pseudoResponse(HttpServletResponse rs) {
    PrintWriter pw = null;//from  w  ww.  j a v  a2 s  . co m
    try {
        rs.setContentType("text/plain;charset=UTF-8");
        pw = rs.getWriter();
        IOUtils.write("done", pw);
    } catch (IOException ex) {
        FamLog.exception(ex, 200911182012l);
    } finally {
        IOUtils.closeQuietly(pw);
    }
    return null;
}

From source file:demo.wseventing.CreateSubscriptionServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {//from  www .ja  v a 2 s  .  c om
        resp.getWriter().append("<html><body>");

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(EventSourceEndpoint.class);
        factory.setAddress("http://localhost:8080/ws_eventing/services/EventSource");
        EventSourceEndpoint requestorClient = (EventSourceEndpoint) factory.create();

        String expires = null;
        if (req.getParameter("expires-set") == null) {
            expires = req.getParameter("expires");
        } else {
            if (!req.getParameter("expires-set").equals("false")) {
                expires = req.getParameter("expires");
            }
        }

        Subscribe sub = createSubscribeMessage(req.getParameter("targeturl"),
                req.getParameter("filter-set") == null ? req.getParameter("filter") : null, expires);

        resp.getWriter().append("<h3>Subscription request</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(sub));

        SubscribeResponse subscribeResponse = requestorClient.subscribeOp(sub);

        resp.getWriter().append("<h3>Response from Event Source</h3>");
        resp.getWriter().append(convertJAXBElementToStringAndEscapeHTML(subscribeResponse));

        resp.getWriter().append("<br/><a href=\"index.jsp\">Back to main page</a>");
        resp.getWriter().append("</body></html>");
    } catch (Exception e) {
        throw new ServletException(e);
    }

}

From source file:ict.DoLoginServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w  w . ja v  a  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 {
    PrintWriter out = response.getWriter();
    try {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("WSPU");
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();

        String _request = request.getParameter("AAA");
        String userID = new String(Base64.decodeBase64(_request));

        String _request_ = request.getParameter("BBB");
        String userPassword = new String(Base64.decodeBase64(_request_));

        //String userID = request.getParameter("userID");
        //String userPassword = request.getParameter("userPassword");
        User tmp = new User();
        tmp.setUserID(userID);
        tmp.setPassword(userPassword);
        System.out.println("*****" + tmp.getUserID());

        User user = entityManager.find(User.class, tmp.getUserID());
        if (user.getPassword().equals(tmp.getPassword())) {
            entityManager.getTransaction().commit();
            entityManager.close();
            entityManagerFactory.close();
            request.getSession(true).setAttribute("user", user.getUserName());
        }

    } catch (Exception e) {
        System.out.println("****ERROR:****" + e.getMessage());
    }
    response.sendRedirect("index.jsp");
}

From source file:CompileServlet.java

/**
 * Main servlet entry point. The servlet reads a stylesheet from the
 * URI specified by the "sheet" parameter. The compiled Java class
 * ends up in the CWD of the web server (a better solution would be
 * to have an environment variable point to a translet directory).
 *///  w  w  w.  j  av a  2  s.  c  o  m
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String stylesheetName = request.getParameter("sheet");

    out.println("<html><head>");
    out.println("<title>Servlet Stylesheet Compilation</title>");
    out.println("</head><body>");

    if (stylesheetName == null) {
        out.println("<h1>Compilation error</h1>");
        out.println("The parameter <b><tt>sheet</tt></b> " + "must be specified");
    } else {
        XSLTC xsltc = new XSLTC();

        xsltc.init();
        xsltc.compile(new URL(stylesheetName));
        out.println("<h1>Compilation successful</h1>");
        out.println("The stylesheet was compiled into the translet " + "class " + xsltc.getClassName()
                + " and is now " + "available for transformations on this server.");
    }
    out.println("</body></html>");
}

From source file:comsat.sample.servlet.SampleServletApplication.java

@SuppressWarnings("serial")
@Bean//from  w ww . j  a v  a  2s  .  c om
public Servlet dispatcherServlet() {
    return new FiberHttpServlet() {
        @Override
        @Suspendable
        public void doGet(HttpServletRequest req, HttpServletResponse res)
                throws ServletException, IOException {
            try {
                Fiber.sleep(10);
                res.setContentType("text/plain");
                res.getWriter().append("Hello World");
            } catch (InterruptedException | SuspendExecution ex) {
                throw new AssertionError(ex);
            }
        }
    };
}

From source file:com.imagelake.android.privilages.Servlet_privilages.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from w  ww  . j  a va  2s  .c  o  m*/

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

        if (user_type != null) {

            if (Integer.parseInt(user_type) != 4) {
                privilageArray = new JSONArray();

                li = pdi.listAll(Integer.parseInt(user_type));

                if (!li.isEmpty()) {

                    for (Privilages privilages : li) {
                        if (privilages.getState() == 1) {

                            inf = infs.getInterfaceName(privilages.getInterface_interface_id());

                            JSONObject jo = new JSONObject();
                            jo.put("interface", inf.getDisplay_name());
                            jo.put("imgId", inf.getImg_id());
                            System.out.println(inf.getImg_id());
                            privilageArray.add(jo);

                        }
                    }

                    out.write("json=" + privilageArray.toJSONString());

                } else {
                    out.write("msg=No privilages.");
                }
            } else {
                out.write("msg=Incorrect user type.");
            }

        } else {
            out.write("msg=User type error.");
        }

    } catch (Exception e) {
        e.printStackTrace();
        out.write("msg=Internal server error,Please try again later.");
    }

}

From source file:fr.aliasource.webmail.proxy.UpdateSieve.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    logger.info("doGet on updateSieve servlet.");
    resp.setContentType("text/plain");
    resp.getWriter().println("UpdateSieve servlet should be called with a POST HTTP request.");
}