List of usage examples for javax.servlet ServletOutputStream println
public void println(double d) throws IOException
double
value to the client, followed by a carriage return-line feed (CRLF). From source file:DeleteClobFromOracleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Connection conn = null;//from w w w .j a v a 2s . c o m PreparedStatement pstmt = null; String id = "001"; ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>Delete CLOB Record</title></head>"); try { conn = getConnection(); pstmt = conn.prepareStatement("delete from DataFiles where id = ?"); pstmt.setString(1, id); pstmt.executeUpdate(); out.println("<body><h4>deleted CLOB record with id=" + id + "</h4></body></html>"); } catch (Exception e) { out.println("<body><h4>Error=" + e.getMessage() + "</h4></body></html>"); } finally { try { pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:InsertClobToMySqlServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String clobData = null;//ww w. j a v a 2 s . co m Connection conn = null; String id = "001"; String name = "fileName"; String fileAsURL = "http://yourwebsite/fileName.dat"; ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>Insert Clob To MySql Servlet</title></head>"); try { conn = getConnection(); clobData = getClobsContentAsString(fileAsURL); insertCLOB(conn, id, name, clobData); out.println("<body><h4>OK: inserted a new record with id=" + id + "</h4></body></html>"); } catch (Exception e) { e.printStackTrace(); out.println("<body><h4>Error: " + e.getMessage() + "</h4></body></html>"); } }
From source file:DeleteClobFromServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Connection conn = null;//from w ww. ja v a2 s. c om PreparedStatement pstmt = null; String id = "0001"; ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>Delete CLOB Record</title></head>"); try { conn = getHSQLConnection(); pstmt = conn.prepareStatement("delete from DataFiles where id = ?"); pstmt.setString(1, id); pstmt.executeUpdate(); out.println("<body><h4>deleted CLOB record with id=" + id + "</h4></body></html>"); } catch (Exception e) { out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>"); } finally { try { pstmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream out = res.getOutputStream(); res.setContentType("text/plain"); String file = req.getPathInfo(); if (file == null) { out.println("Extra path info was null; should be a resource to view"); return;/*from w w w .ja va2 s.c o m*/ } URL url = getServletContext().getResource(file); if (url == null) { out.println("Resource " + file + " not found"); return; } URLConnection con = null; try { con = url.openConnection(); con.connect(); } catch (IOException e) { out.println("Resource " + file + " could not be read: " + e.getMessage()); return; } }
From source file:org.projectforge.web.imagecropper.UploadImageFileTemporary.java
/** * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) *///from w ww . j av a2 s .co m protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { log.debug("Start doPost"); final PFUserDO user = UserFilter.getUser(request); if (user == null) { log.warn("Calling of UploadImageFileTemp without logged in user."); return; } // check if the sent request is of the type multi part final boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart == false) { log.warn("The request is not of the type multipart"); return; } try { // Parse the request final FileItem imgFile = getImgFileItem(request); // get the file item of the multipart request // everything ok so far so process the file uploaded if (imgFile == null || imgFile.getSize() == 0) { log.warn("No file was uploaded, aborting!"); return; } if (imgFile.getSize() > MAX_SUPPORTED_FILE_SIZE) { log.warn("Maximum file size exceded for file '" + imgFile.getName() + "': " + imgFile.getSize()); return; } final File tmpImageFile = ImageCropperUtils.getTempFile(user); // Temporary file log.info("Writing tmp file: " + tmpImageFile.getAbsolutePath()); try { // Write new File imgFile.write(tmpImageFile); } catch (Exception e) { log.error("Could not write " + tmpImageFile.getAbsolutePath(), e); } } catch (FileUploadException ex) { log.warn("Failure reading the multipart request"); log.warn(ex.getMessage(), ex); } final ServletOutputStream out = response.getOutputStream(); out.println("text/html"); }
From source file:org.medici.bia.controller.sitemap.SitemapIndexController.java
/** * //w w w . j av a 2 s .c o m * @return */ @RequestMapping(method = RequestMethod.GET) public void setupPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { File sitemapIndexFile = new File(ApplicationPropertyManager.getApplicationProperty("path.tmpdir") + "sitemapIndex" + UUID.randomUUID() + ".xml"); try { List<SitemapIndex> list = getSitemapService().getSitemapIndex(); String website = ApplicationPropertyManager.getApplicationProperty("website.protocol") + "://" + ApplicationPropertyManager.getApplicationProperty("website.domain"); SitemapIndexGenerator sitemapIndexGenerator = new SitemapIndexGenerator(website, sitemapIndexFile); for (int i = 0; i < list.size(); i++) { sitemapIndexGenerator.addUrl(list.get(i).getLocation()); } // Write temporary file... sitemapIndexGenerator.write(); httpServletResponse.setContentType("application/xml"); ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream(); servletOutputStream.println(FileUtils.readFileToString(sitemapIndexFile)); httpServletResponse.getOutputStream().flush(); } catch (ApplicationThrowable applicationThrowable) { logger.error("ApplicationThrowable error: " + applicationThrowable.getMessage()); } catch (MalformedURLException e) { logger.error("Error: " + e.getMessage()); } catch (IOException e) { logger.error("Error: " + e.getMessage()); } finally { sitemapIndexFile.delete(); } }
From source file:org.energyos.espi.datacustodian.web.api.ManageRESTController.java
/** * Provides access to administrative commands through the pattern: * DataCustodian/manage?command=[resetDataCustodianDB | * initializeDataCustodianDB]//from w w w. jav a 2 s . co m * * @param response * Contains text version of stdout of the command * @param params * [["command" . ["resetDataCustodianDB" | * "initializeDataCustodianDB"]]] * @param stream * @throws IOException */ @RequestMapping(value = Routes.DATA_CUSTODIAN_MANAGE, method = RequestMethod.GET, produces = "text/plain") @ResponseBody public void doCommand(HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { response.setContentType(MediaType.TEXT_PLAIN_VALUE); try { try { String commandString = params.get("command"); System.out.println("[Manage] " + commandString); ServletOutputStream output = response.getOutputStream(); output.println("[Manage] Restricted Management Interface"); output.println("[Manage] Request: " + commandString); String command = null; // parse command if (commandString.contains("resetDataCustodianDB")) { command = "/etc/OpenESPI/DataCustodian/resetDatabase.sh"; } else if (commandString.contains("initializeDataCustodianDB")) { command = "/etc/OpenESPI/DataCustodian/initializeDatabase.sh"; } if (command != null) { Process p = Runtime.getRuntime().exec(command); p.waitFor(); output.println("[Manage] Result: "); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = reader.readLine(); while (line != null) { System.out.println("[Manage] " + line); output.println("[Manage]: " + line); line = reader.readLine(); } reader = new BufferedReader(new InputStreamReader(p.getErrorStream())); output.println("[Manage] Errors: "); line = reader.readLine(); while (line != null) { System.out.println("[Manage] " + line); output.println("[Manage]: " + line); line = reader.readLine(); } } } catch (IOException e1) { } catch (InterruptedException e2) { } System.out.println("[Manage] " + "Done"); } catch (Exception e) { System.out.printf("**** [Manage] Error: %s\n", e.toString()); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.controlj.green.bulktrend.trendserver.SearchServlet.java
private void writeErrorInRow(HttpServletResponse resp, String msg) throws IOException { ServletOutputStream out = resp.getOutputStream(); out.println("<tr><td colspan=\"100\">Error: " + msg + "</td></tr>"); out.flush();/* ww w .j a v a 2 s.c om*/ }
From source file:jetbrains.buildServer.torrent.web.TorrentLinksController.java
@Nullable @Override//from w ww . j a v a 2 s . c o m protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception { String buildIdParam = request.getParameter("buildId"); if (buildIdParam == null) { return null; } try { long buildId = Long.parseLong(buildIdParam); SBuild build = myServer.findBuildInstanceById(buildId); if (build != null && myConfigurator.isDownloadEnabled()) { Collection<File> torrentFiles = myTorrentsManager.getTorrentFiles(build); File baseDir = myTorrentsManager.getTorrentFilesBaseDir(build); List<String> paths = getArtifactsWithTorrents(baseDir, torrentFiles); response.setContentType("text/plain"); ServletOutputStream output = response.getOutputStream(); try { for (String name : paths) { output.println(name); } } finally { output.close(); } } } catch (Exception e) { // ignore } return null; }
From source file:org.spiffyui.hellospiffyauth.server.SampleAuthServer.java
@Override public void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); ServletOutputStream out = response.getOutputStream(); StringBuffer buff = new StringBuffer(); buff.append("{\"Status\":\"OK\"}"); out.println(buff.toString()); }