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:org.openmrs.module.radiology.web.controller.maintainer.MaintainController.java

/**
 * Accept a test//w w  w . ja v  a2 s.  co  m
 * 
 * @param orderId
 * @param model
 * @return id of accepted radiology test
 * @throws IOException 
 */
@RequestMapping(value = "/module/radiology/maintain/checkRadiologyForm.htm", method = RequestMethod.GET)
public void checkRadiology(HttpServletResponse response) throws IOException {

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter writer = response.getWriter();
    Pattern pattern = Pattern.compile("name=\"[a-zA-Z0-9 ]*\"");
    List<RadiologyForm> forms = Context.getService(RadiologyService.class).getAllRadiologyForms();
    Set<String> invalidConcepts = new HashSet<String>();
    Set<Integer> formIds = new HashSet<Integer>();
    for (RadiologyForm form : forms) {
        Matcher matcher = pattern.matcher(form.getContent());
        while (matcher.find()) {
            String name = matcher.group().substring(6, matcher.group().length() - 1);
            Concept concept = Context.getConceptService().getConcept(name);
            if (concept == null) {
                invalidConcepts.add(name);
                formIds.add(form.getId());
            }
        }
    }
    writer.println(formIds);
    for (String name : invalidConcepts) {
        writer.println(name);
    }
}

From source file:org.tdmx.server.sx.Servlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    PrintWriter writer = response.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Hello World Servlet</title></head>");
    writer.println("<body>");
    writer.println("Hello World! How are you doing? secure=" + request.isSecure());
    // writer.println(" AccountId=" + accountService.getActivePartitionId());

    writer.println("</body>");
    writer.println("</html>");
    writer.close();//from  w  w  w.  ja v a  2s  . c  o  m

}

From source file:com.test.servlet.RegisterController.java

@Override
public void setResponse(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter writer = response.getWriter();
    String email = getParam(RequestParam.email.toString());
    String password = getParam(RequestParam.password.toString());
    String firstName = getParam(RequestParam.first_name.toString());
    String lastName = getParam(RequestParam.last_name.toString());
    String errorMsg = null;/*from   ww  w.j ava 2s.c  om*/
    if (Utility.isStringEmpty(email)) {
        writer.print(
                Utility.generalErrorMessage(ResponseCode.email_not_provided.toString(), "Email is required!"));
        return;
    }
    if (Utility.isStringEmpty(password)) {
        writer.print(Utility.generalErrorMessage(ResponseCode.password_not_provided.toString(),
                "Password is required!"));
        return;
    }

    DBUtility dbUtil = new DBUtility(servlet);
    SessionGenerator generator = SessionGenerator.getInstance();
    User user = new User();
    user.setEmail(email);
    user.setFirstName(firstName);
    user.setLastname(lastName);
    user.setPassword(password);
    user.setRegistration_key(generator.nextSessionId());
    boolean result = dbUtil.insertUser(user);
    if (result) {
        try {
            MailUtility.sendVerificationEmail(user);
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }

        JSONObject jReponse = new JSONObject();
        jReponse.put(JSONKey.status.toString(), 0);
        jReponse.put(JSONKey.message.toString(),
                "Registration successful. Check your email for instructions on how to verify your account.");

        writer.print(jReponse.toString());
    } else {
        writer.print(Utility.generalErrorMessage(ResponseCode.email_exists.toString(),
                "Email address already exists"));
    }
}

From source file:MainServer.ImageUploadServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    try {/*  w  ww .ja  v  a 2 s .c o  m*/
        List<FileItem> items = this.upload.parseRequest(request);
        if (items != null && !items.isEmpty()) {
            for (FileItem item : items) {
                String filename = item.getName();
                String filepath = fileDir + File.separator + filename;
                System.out.println("File path: " + filepath);
                File file = new File(filepath);
                InputStream inputStream = item.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(inputStream);
                FileOutputStream fos = new FileOutputStream(file);
                int f;
                while ((f = bis.read()) != -1) {
                    fos.write(f);
                }
                fos.flush();
                fos.close();
                bis.close();
                inputStream.close();
                System.out.println("File: " + filename + "Uploaded");
            }
        }
        System.out.println("Uploaded!");
        out.write("Uploaded!");
    } catch (FileUploadException | IOException e) {
        System.out.println(e);
        out.write(fileDir);
    }
}

From source file:com.me.controller.homecontroller.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

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

    ArrayList<csvfile> a = new ArrayList<csvfile>();
    try {//ww  w  .  j  a va 2  s . c o  m
        Class.forName("org.relique.jdbc.csv.CsvDriver");
        Connection conn = DriverManager.getConnection(
                "jdbc:relique:csv:C:\\Users\\user\\Documents\\NetBeansProjects\\Assignment5WebPart5\\web\\WEB-INF\\jsp");
        Statement stmt = conn.createStatement();
        int c1, d;

        c1 = Integer.parseInt(request.getParameter("count1"));
        d = (c1 - 1) * 100;

        System.out.println(d);
        ResultSet resultMessages = stmt.executeQuery("SELECT * FROM SalesOrder LIMIT 100 OFFSET " + d + "");

        while (resultMessages.next()) {
            csvfile messageBean = new csvfile();
            messageBean.setSalesOrderID(resultMessages.getString("SalesOrderID"));
            messageBean.setRevisionNumber(resultMessages.getString("RevisionNumber"));
            messageBean.setOrderDate(resultMessages.getString("OrderDate"));
            messageBean.setDueDate(resultMessages.getString("DueDate"));
            messageBean.setShipDate(resultMessages.getString("ShipDate"));
            messageBean.setStatus(resultMessages.getString("Status"));
            messageBean.setOnlineOrderFlag(resultMessages.getString("OnlineOrderFlag"));
            messageBean.setSalesOrderNumber(resultMessages.getString("SalesOrderNumber"));
            messageBean.setPurchaseOrderNumber(resultMessages.getString("PurchaseOrderNumber"));
            messageBean.setAccountNumber(resultMessages.getString("AccountNumber"));
            messageBean.setCustomerID(resultMessages.getString("CustomerID"));
            messageBean.setSalesPersonID(resultMessages.getString("SalesPersonID"));
            messageBean.setTerritoryID(resultMessages.getString("TerritoryID"));
            messageBean.setBillToAddressID(resultMessages.getString("BillToAddressID"));
            messageBean.setShipToAddressID(resultMessages.getString("ShipToAddressID"));
            messageBean.setShipMethodID(resultMessages.getString("ShipMethodID"));
            messageBean.setCreditCardID(resultMessages.getString("CreditCardID"));
            messageBean.setCreditCardApprovalCode(resultMessages.getString("CreditCardApprovalCode"));
            messageBean.setCurrencyRateID(resultMessages.getString("CurrencyRateID"));
            messageBean.setSubTotal(resultMessages.getString("SubTotal"));
            messageBean.setTaxAmt(resultMessages.getString("TaxAmt"));
            messageBean.setFreight(resultMessages.getString("Freight"));
            messageBean.setTotalDue(resultMessages.getString("TotalDue"));
            messageBean.setComment(resultMessages.getString("Comment"));
            messageBean.setModifiedDate(resultMessages.getString("ModifiedDate"));
            a.add(messageBean);
        }
        // Clean up
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    JSONObject obj = new JSONObject();
    obj.put("users", a);
    out.println(obj);

    return null;
}

From source file:com.laxser.blitz.web.instruction.TextInstruction.java

private void sendResponse(HttpServletResponse response, String text) throws IOException {
    if (StringUtils.isNotEmpty(text)) {
        PrintWriter out = response.getWriter();
        if (logger.isDebugEnabled()) {
            logger.debug("write text to response:" + text);
        }//ww w.ja  va2s .  co  m
        out.print(text);
    }
}

From source file:ch.unifr.pai.twice.widgets.mpProxyScreenShot.server.ReadOnlyPresentation.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter w = resp.getWriter();
    for (String uuid : uuidToScreenshot.keySet()) {
        Screenshot s = uuidToScreenshot.get(uuid);

        w.print("<div style=\"width:");
        w.print((int) Math.ceil((double) s.width * scaleFactor));
        w.print("px; height:");
        w.print((int) Math.ceil((double) s.height * scaleFactor));
        w.print("px; overflow:hidden; display:inline-block;\">");
        w.print("<iframe ");
        w.print("name=\"");
        w.print(uuid);/* w w w  . jav a2s .co  m*/
        w.print("\" style=\"width:100%; height:100%;\" src=\"");
        w.print(SimpleHttpUrlConnectionServletFilter.getServletPath(req));
        w.print("/" + s.url + "/");
        w.print("miceScreenShot?uuid=" + uuid);
        w.print("\"></iframe></div>");
    }
    w.flush();
    w.close();
    return;
}

From source file:fr.penet.servlet.StartCrawlServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");
    String seed = req.getParameter("seed");
    if (StringUtils.isEmpty(seed)) {
        resp.getWriter().println("Error : empty seed parameter");
        return;//from  ww  w .jav a 2 s.c o m
    }
    String threads = req.getParameter("threads");
    int threadInt = 5;
    if (StringUtils.isNumeric(threads)) {
        threadInt = Integer.parseInt(threads);
    }
    CustomCrawler crawler = new CustomCrawler();
    int runId = crawler.startCollectUrls(seed, threadInt);
    resp.getWriter().println("Crawler run with id " + runId + " and " + threadInt + " threads started");
}

From source file:GetCookiesServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Cookie[] cookies = request.getCookies();

    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.println("<B>");
    for (int i = 0; i < cookies.length; i++) {
        String name = cookies[i].getName();
        String value = cookies[i].getValue();
        pw.println("name = " + name + "; value = " + value);
    }/*from w  ww . j a va2s .c  om*/
    pw.close();
}

From source file:com.example.appengine.autocomplete.ProductNameAutocompleteJSONServlet.java

private void doDebugging(List<String> suggestions, HttpServletResponse response) throws IOException {
    PrintWriter out = response.getWriter();

    out.println("<br/>");
    out.println("<b>Results:</b> " + suggestions.size());
    out.println("<br/>");
    out.println("<br/>");
    for (String s : suggestions) {
        out.println(s);//w  w w.  j  a  v  a 2 s .com
        out.println("<br/>");
    }
}