List of usage examples for javax.servlet.http HttpServletResponse getWriter
public PrintWriter getWriter() throws IOException;
PrintWriter
object that can send character text to the client. From source file:com.ci6225.marketzone.servlet.seller.AddProductServlet.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response)//from ww w .ja v a 2s .c o m */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); }
From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter writer = response.getWriter(); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/xml"); try {/*from www .j a v a 2 s . co m*/ ServletInputStream stream = request.getInputStream(); String requestBody = IOUtils.toString(stream); Integer mathResult = getMathResult(requestBody); writeMathResult(writer, mathResult); } catch (Exception e) { writeSoapError(writer, e.getMessage()); } writer.flush(); writer.close(); }
From source file:cz.incad.kramerius.client.CacheServlet.java
private void loadFromFile(HttpServletRequest req, HttpServletResponse resp) throws IOException { try {// w w w .j a va2s . c o m String filename = getPath() + req.getParameter("f"); File f = new File(filename); resp.getWriter().write(FileUtils.readFileToString(f, "UTF-8")); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not load file: " + e.toString()); } }
From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java
/** * If the document is HTML, this method processes its content in order to * rewrite the URLs it includes/*from w ww.j a v a 2s . co m*/ * * @param response HTTP response * @param method HTTP method * @param url document url * @param loginUrl login url * @param contenType content Type * * @throws IOException * @throws ParserException */ public static void processHTML(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl, String contentType) throws IOException, ParserException { logger.debug("Processing an HTML document"); String stream = null; Parser parser = null; NodeVisitor visitor = null; // Retrieve HTML stream stream = readFully(new InputStreamReader(method.getResponseBodyAsStream())); // Protection if (stream != null) { logger.debug("Stream content size: " + stream.length()); // Parse HTML stream to replace any links to include the path to the valve parser = Parser.createParser(stream, null); // Instantiate visitor visitor = new HTTPVisitor(url, loginUrl); // Parse nodes parser.visitAllNodesWith(visitor); // Get writer PrintWriter out = response.getWriter(); // Push HTML content if (out != null) { out.flush(); out.print(((HTTPVisitor) visitor).getModifiedHTML()); out.close(); logger.debug("Wrote: " + ((HTTPVisitor) visitor).getModifiedHTML().length()); } response.setHeader("Content-Type", contentType); // Garbagge collect stream = null; parser = null; visitor = null; } }
From source file:com.ns.cm.ProvisionServlet.java
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO/*from www . ja v a 2s. c om*/ // PrintWriter out = response.getWriter(); out.println("Processed doDelete"); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); }
From source file:com.angstoverseer.web.servlet.CommandServlet.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final UserService userService = UserServiceFactory.getUserService(); if (userService.getCurrentUser() == null) { response.getWriter().print("Error: User not authenticated."); } else {/*w w w. j a v a 2 s. com*/ final String command = request.getParameter("command"); final String email = userService.getCurrentUser().getEmail(); final String answer = commandService.process(command, email); response.getWriter().print(answer); } }
From source file:org.picketlink.test.trust.servlet.GatewayServlet.java
private void authInfoAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); out.println("GatewayAuthentication=Success"); out.println("ClassName=" + this.getClass().getName()); out.println("--------------------------------------"); out.println("UserPrincipal=" + req.getUserPrincipal().getName()); out.println("--------------------------------------"); Subject subject = SecurityAssociation.getSubject(); if (subject != null) { out.println("Subject=" + subject); out.println("--------------------------------------"); out.println("PublicCredentialsSize=" + subject.getPublicCredentials().size()); out.println("--------------------------------------"); int i = 0; for (Object c : subject.getPublicCredentials()) { out.println("Credential[" + i + "]=" + c.toString()); i++;//from w ww.ja v a 2 s.c o m } } }
From source file:edu.cornell.library.scholars.webapp.controller.api.DistributeDataApiController.java
private void do403Forbidden(HttpServletResponse resp) throws IOException { log.debug("403Forbidden"); resp.setStatus(403);// w w w. j a v a 2 s. com resp.getWriter().println("Not authorized for this action."); }
From source file:org.shredzone.cilla.plugin.flattr.FlattrFragmentRenderer.java
/** * Fetches the flattr click counter of a thing as AJAX request. *///from ww w . j av a 2 s. c o m @View(pattern = "/ajax/flattr/${#thingid}-count.html", signature = { "#thingid" }, qualifier = "ajax") public void flattrCount(@PathPart("#thingid") String thingid, HttpServletRequest req, HttpServletResponse resp) throws IOException { int count = flattrPublicationService.clickCount(Thing.withId(thingid)); resp.getWriter().append("<span class=\"flattr-count\"><span>").append(String.valueOf(count)) .append("</span></span>"); }
From source file:in.raster.oviyam.servlet.LanguageServlet.java
/** * Processes requests for both HTTP/* ww w .j ava2s. c om*/ * <code>GET</code> and * <code>POST</code> methods. * * @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 { String option = request.getParameter("option"); File tempDir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir"); LanguageHandler langHandler = new LanguageHandler(tempDir.getParent()); /*String warName = request.getContextPath().substring(1); String tmpDirPath = tempDir.getAbsolutePath(); tmpDirPath = tmpDirPath.substring(0, tmpDirPath.indexOf(warName)); LanguageHandler langHandler = new LanguageHandler(tmpDirPath);*/ if (option.equals("set")) { String language = request.getParameter("language"); // Language lang = new Language(); //lang.setLanguage(language); langHandler.updateLanguage(language); out.println("Success"); } else if (option.equals("getall")) { response.setContentType("application/json"); JSONArray langArray = new JSONArray(langHandler.getLanguage()); out.println(langArray); } else { out.println(langHandler.getCurrentLanguage()); } } finally { out.close(); } }