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:bookmarksave.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); System.out.println("executed"); String productid = request.getParameter("productid1"); Date date = new Date(); SimpleDateFormat form = new SimpleDateFormat("dd/MM/yyyy"); HttpSession session = request.getSession(true); String username = (String) session.getAttribute("username"); System.out.println(username); String bookmarkdate = form.format(date); bookmarksbean bookmark = new bookmarksbean(); bookmark.setProductid(productid);// w ww . j av a 2s . c om bookmark.setUsername(username); bookmark.setDateofbookmark(bookmarkdate); System.out.println(username + " " + productid); int count = bookmark.save(); out.println("Bookmark Added"); }
From source file:com.job.portal.servlets.JobApplicationsServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); JSONObject obj = null;/*from w w w.j a v a 2s. com*/ JSONArray arr = null; JobApplicationsManager jam = new JobApplicationsManager(); try { String param = request.getParameter("param"); if (param != null) { if (param.equalsIgnoreCase("apply")) { obj = jam.apply(request); out.print(obj); } else if (param.equalsIgnoreCase("showApplied")) { arr = jam.getAppliedJobs(request); out.print(arr); } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } finally { out.close(); } }
From source file:EnvEntry.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); try {//ww w .j av a 2 s . c o m Context initCtx = new InitialContext(); NamingEnumeration e = initCtx.listBindings("java:comp/env"); while (e.hasMore()) { Binding binding = (Binding) e.next(); out.println("Name: " + binding.getName()); out.println("Type: " + binding.getClassName()); out.println("Value: " + binding.getObject()); out.println(); } } catch (NamingException e) { e.printStackTrace(out); } }
From source file:HelloJapan.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain; charset=Shift_JIS"); PrintWriter out = res.getWriter(); res.setHeader("Content-Language", "ja"); Locale locale = new Locale("ja", ""); DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Japanese:"); out.println("\u4eca\u65e5\u306f\u4e16\u754c"); // Hello World out.println(full.format(new Date())); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); if (lastprime == 0) { out.println("Still searching for first prime..."); } else {//from w w w . java2s. c o m out.println("The last prime discovered was " + lastprime); out.println(" at " + lastprimeModified); } }
From source file:com.imagelake.android.category.Servlet_categories.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); CategoriesDAOImp categoryDAOImp = new CategoriesDAOImp(); JSONArray ja = new JSONArray(); ArrayList<Categories> categoriesList = (ArrayList<Categories>) categoryDAOImp.listAllCategories(); if (!categoriesList.isEmpty()) { for (Categories cc : categoriesList) { JSONObject jo = new JSONObject(); jo.put("id", cc.getCategory_id()); jo.put("cat", cc.getCategory()); ja.add(jo);// ww w .j av a2 s. com } out.write("json=" + ja.toJSONString()); } else { JSONObject jo = new JSONObject(); jo.put("id", 0); jo.put("cat", "No category found."); ja.add(jo); out.write("json=" + ja.toJSONString()); } }
From source file:com.triage.radium.testweb.RuntimeExecServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String listCommand = "ls"; PrintWriter out = resp.getWriter(); if (SystemUtils.IS_OS_WINDOWS) { listCommand = "dir"; }//from w w w. j a v a2 s.co m try { String output = new ExecCommand().executeCommand(listCommand); out.println("SUCCESS"); out.println(output); } catch (Exception e) { out.println("ERROR"); e.printStackTrace(out); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String remoteUser = req.getRemoteUser(); if (remoteUser == null) { out.println("Welcome!"); } else {/*www .ja va 2 s . c o m*/ out.println("Welcome, " + remoteUser + "!"); Date lastAccess = (Date) accesses.get(remoteUser); if (lastAccess == null) { out.println("This is your first visit!"); } else { out.println("Your last visit was " + accesses.get(remoteUser)); } if (remoteUser.equals("YourFirendName")) { out.println("Shall we play a game?"); } accesses.put(remoteUser, new Date()); } }
From source file:com.quatico.base.aem.test.api.setup.Tags.java
@Override public String renderTag(TagSupport tag, PageContext pageContext, String body) throws Exception { StringWriter strWriter = new StringWriter(); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(new PrintWriter(strWriter, true)); if (!mockingDetails(pageContext).isSpy()) { pageContext = spy(pageContext);// ww w. j a va 2 s . c o m } JspWriter jspWriter = new JspWriterImpl(response); doReturn(jspWriter).when(pageContext).getOut(); tag.setPageContext(pageContext); if (Tag.EVAL_BODY_INCLUDE == tag.doStartTag()) { jspWriter.flush(); strWriter.write(body); } jspWriter.flush(); tag.doEndTag(); jspWriter.flush(); tag.release(); return strWriter.toString(); }
From source file:PersonalizedServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String remoteUser = req.getRemoteUser(); if (remoteUser == null) { out.println("Welcome!"); } else {// w ww . j ava 2 s. c o m out.println("Welcome, " + remoteUser + "!"); Date lastAccess = (Date) accesses.get(remoteUser); if (lastAccess == null) { out.println("This is your first visit!"); } else { out.println("Your last visit was " + accesses.get(remoteUser)); } if (remoteUser.equals("User A")) { out.println("HI."); } accesses.put(remoteUser, new Date()); } }