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:DateServlet.java

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

    HttpSession hs = request.getSession(true);

    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.print("<B>");

    Date date = (Date) hs.getAttribute("date");
    if (date != null) {
        pw.print("Last access: " + date + "<br>");
    }//ww w  .j  a  v  a  2 s  .c o m

    date = new Date();
    hs.setAttribute("date", date);
    pw.println("Current date: " + date);
}

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

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    ModelAndView mv = new ModelAndView();

    String b1 = request.getParameter("item1");
    String b2 = request.getParameter("item2");
    String b3 = request.getParameter("item3");
    String b4 = request.getParameter("item4");
    String b5 = request.getParameter("item5");
    String b6 = request.getParameter("item6");
    String b7 = request.getParameter("item7");
    String b8 = request.getParameter("item8");
    String b9 = request.getParameter("item9");
    String b10 = request.getParameter("item10");
    String b11 = request.getParameter("item11");
    String b12 = request.getParameter("item12");
    String b13 = request.getParameter("item13");
    String b14 = request.getParameter("item14");
    String b15 = request.getParameter("item15");
    String b16 = request.getParameter("item16");
    String b17 = request.getParameter("item17");
    String b18 = request.getParameter("item18");
    String b19 = request.getParameter("item19");
    String b20 = request.getParameter("item20");
    String b21 = request.getParameter("item21");
    String b22 = request.getParameter("item22");
    String b23 = request.getParameter("item23");
    String b24 = request.getParameter("item24");
    String b25 = request.getParameter("item25");

    Connection conn = Dao.getConnectionJDBC();
    PreparedStatement ps;//from   w ww.  j ava2s  .co  m
    System.out.println("I am here");
    String query = "insert into salesordertable values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    ps = conn.prepareStatement(query);
    ps.setString(1, b1);
    ps.setString(2, b2);
    ps.setString(3, b3);
    ps.setString(4, b4);
    ps.setString(5, b5);

    ps.setString(6, b6);
    ps.setString(7, b7);
    ps.setString(8, b8);
    ps.setString(9, b9);
    ps.setString(10, b10);

    ps.setString(11, b11);
    ps.setString(12, b12);
    ps.setString(13, b13);
    ps.setString(14, b14);
    ps.setString(15, b15);

    ps.setString(16, b16);
    ps.setString(17, b17);
    ps.setString(18, b18);
    ps.setString(19, b19);
    ps.setString(20, b20);

    ps.setString(21, b21);
    ps.setString(22, b22);
    ps.setString(23, b23);
    ps.setString(24, b24);
    ps.setString(25, b25);

    ps.executeUpdate();

    return null;
}

From source file:eu.delving.services.controller.SearchApiController.java

@RequestMapping("/api/open-search")
public void openSearchServiceController(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    response.getWriter()
            .write(OpenSearchService.parseHttpServletRequest(request, beanQueryModelFactory, launchProperties));
    response.getWriter().close();//w  ww.  j  ava  2s . co  m
}

From source file:eu.delving.services.controller.SearchApiController.java

@RequestMapping("/api/open-search.xml")
public void openSearchServiceDescriptionController(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(
            OpenSearchService.renderDescriptionDocument(request, beanQueryModelFactory, launchProperties));
    response.getWriter().close();/*ww  w . j  a  v a2s .  c  om*/
}

From source file:net.oletalk.hellospringboot.controller.S3Controller.java

@RequestMapping("/from")
void from(@RequestParam(value = "key") String objectKey, HttpServletResponse response) {
    try {//w w w. ja v  a 2s. co m
        service.writeDocument(objectKey, response.getOutputStream());
    } catch (IOException ioe) {
        try {
            response.getWriter().println("Error in response: " + ioe.toString());
        } catch (IOException e) {
            LOG.error(e);
        }
    } catch (S3Exception ex) {
        LOG.error(ex);
    }
}

From source file:edu.lafayette.metadb.web.controlledvocab.ShowVocabList.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*//*from w ww.  j  a v 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();
    String term = request.getParameter("term");
    term = term == null ? "" : term.toLowerCase();
    JSONArray vocabs = new JSONArray();
    try {
        String userName = null;
        HttpSession session = request.getSession(false);
        if (session != null)
            userName = (String) session.getAttribute("username");

        ArrayList<String> vocabList = new ArrayList<String>(ControlledVocabDAO.getControlledVocabs(userName));
        if (!vocabList.isEmpty()) {
            for (String v : vocabList) {
                if (v.toLowerCase().startsWith(term))
                    vocabs.put(v);
            }
        }
        out.print(vocabs);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    out.flush();
}

From source file:com.adobe.epubcheck.web.EpubCheckServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    PrintWriter out = resp.getWriter();
    if (!ServletFileUpload.isMultipartContent(req)) {
        out.println("Invalid request type");
        return;//ww  w .j a  va2s. c  o  m
    }
    try {
        DiskFileItemFactory itemFac = new DiskFileItemFactory();
        // itemFac.setSizeThreshold(20000000); // bytes
        File repositoryPath = new File("upload");
        repositoryPath.mkdir();
        itemFac.setRepository(repositoryPath);
        ServletFileUpload servletFileUpload = new ServletFileUpload(itemFac);
        List fileItemList = servletFileUpload.parseRequest(req);
        Iterator list = fileItemList.iterator();
        FileItem book = null;
        while (list.hasNext()) {
            FileItem item = (FileItem) list.next();
            String paramName = item.getFieldName();
            if (paramName.equals("file"))
                book = item;
        }
        if (book == null) {
            out.println("Invalid request: no epub uploaded");
            return;
        }
        File bookFile = File.createTempFile("work", "epub");
        book.write(bookFile);
        EpubCheck epubCheck = new EpubCheck(bookFile, out);
        if (epubCheck.validate())
            out.println("No errors or warnings detected");
        book.delete();
    } catch (Exception e) {
        out.println("Internal Server Error");
        e.printStackTrace(out);
    }
}

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

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    ModelAndView mav = new ModelAndView();

    String b1 = request.getParameter("abc1");
    String b2 = request.getParameter("abc2");
    String b3 = request.getParameter("abc3");
    String b4 = request.getParameter("abc4");
    String b5 = request.getParameter("abc5");
    String b6 = request.getParameter("abc6");
    String b7 = request.getParameter("abc7");
    String b8 = request.getParameter("abc8");
    String b9 = request.getParameter("abc9");
    String b10 = request.getParameter("abc10");
    String b11 = request.getParameter("abc11");
    String b12 = request.getParameter("abc12");
    String b13 = request.getParameter("abc13");
    String b14 = request.getParameter("abc14");
    String b15 = request.getParameter("abc15");
    String b16 = request.getParameter("abc16");
    String b17 = request.getParameter("abc17");
    String b18 = request.getParameter("abc18");
    String b19 = request.getParameter("abc19");
    String b20 = request.getParameter("abc20");
    String b21 = request.getParameter("abc21");
    String b22 = request.getParameter("abc22");
    String b23 = request.getParameter("abc23");
    String b24 = request.getParameter("abc24");
    String b25 = request.getParameter("abc25");

    Connection conn = DAO.getConnectionJDBC();
    PreparedStatement ps;// w w  w. j a v  a2s .c o m
    System.out.println("I am here");
    String query = "insert into csv values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    ps = conn.prepareStatement(query);
    ps.setString(1, b1);
    ps.setString(2, b2);
    ps.setString(3, b3);
    ps.setString(4, b4);
    ps.setString(5, b5);

    ps.setString(6, b6);
    ps.setString(7, b7);
    ps.setString(8, b8);
    ps.setString(9, b9);
    ps.setString(10, b10);

    ps.setString(11, b11);
    ps.setString(12, b12);
    ps.setString(13, b13);
    ps.setString(14, b14);
    ps.setString(15, b15);

    ps.setString(16, b16);
    ps.setString(17, b17);
    ps.setString(18, b18);
    ps.setString(19, b19);
    ps.setString(20, b20);

    ps.setString(21, b21);
    ps.setString(22, b22);
    ps.setString(23, b23);
    ps.setString(24, b24);
    ps.setString(25, b25);

    ps.executeUpdate();

    return null;
}

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

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

    try {//from  w  w  w  .  jav a 2 s .c  o  m

        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        ObjectMapper mapper = new ObjectMapper();
        TableMetaDataBL tmBL = new TableMetaDataBL();
        String json = mapper.writeValueAsString(tmBL.loadTree(request));
        out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

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

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");
    String runIdString = req.getParameter("id");
    if (StringUtils.isEmpty(runIdString)) {
        resp.getWriter().println("Error : empty id parameter");
        return;//from  w ww. ja va2 s  .co m
    }
    if (!StringUtils.isNumeric(runIdString)) {
        resp.getWriter().println("Error : id parameter is not an integer");
        return;
    }
    int runId = Integer.parseInt(runIdString);
    CustomCrawler crawler = new CustomCrawler();
    crawler.endCollectUrls(runId);
    resp.getWriter().println("Requested stop of crawl run " + runId);
}