當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.getWriter方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.getWriter方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.getWriter方法的具體用法?Java HttpServletResponse.getWriter怎麽用?Java HttpServletResponse.getWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.getWriter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: printError

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Displays some error output in the HTML response.
 */
private void printError(final String locale, HttpServletResponse resp,
        String errorText) throws IOException {
    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/html; charset=UTF-8");

    String title = Messages.get(locale, "servlet_notification_title");
    String error = Messages.get(locale, "servlet_notification_error",
            new Object[] { errorText });

    String html = Messages.get(locale, "servlet_notification_html",
            new Object[] { title, title, error });
    PrintWriter out = resp.getWriter();

    out.println(html);
    out.close();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:NotificationServlet.java

示例2: execute

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/package-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:17,代碼來源:PackageServletHandler.java

示例3: commence

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException {

	// Authentication failed, send error response.
	response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
	response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName() + "");

	PrintWriter writer = response.getWriter();
	writer.println("HTTP Status 401 : " + authException.getMessage());
}
 
開發者ID:edylle,項目名稱:hockey-game,代碼行數:11,代碼來源:CustomBasicAuthenticationEntryPoint.java

示例4: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();

    String uname = request.getParameter("uname");
       String upwd = request.getParameter("upwd");

    if(uname.equals("root") && upwd.equals("root")) {
        out.println("Login Success"); 
        }else {
      out.println("Login Failure");
    }
}
 
開發者ID:pratikdimble,項目名稱:Servlet_Applet_Communication,代碼行數:13,代碼來源:LoginServlet.java

示例5: preHandle

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object arg2) throws Exception {
	//1、獲取請求的參數
	String requestUrl = request.getServletPath(); 
	String ticket = CookieUtil.getCookieValueByName(request,TitanConstant.TICKET_PREFIX);
	//2、驗證url
	if((null != uncheckUrls) && (0 < uncheckUrls.size()) && (uncheckUrls.contains(requestUrl))){
		return true;
	}else{
		 //3、驗證ticket
		String ticketInRedis = jedisCluster.get(TitanConstant.TICKET_PREFIX + ticket);
		if(StringUtils.isBlank(ticket) || StringUtils.isBlank(ticketInRedis)) {
			logger.warn("登錄攔截,requestUrl:{},ticket:{},ticketInRedis:{}",requestUrl,ticket,ticketInRedis);
			PrintWriter out = response.getWriter();  
	        out.println("<html>");      
	        out.println("<script>");      
	        out.println("window.open ('"+request.getContextPath()+"/login.html','_top')");      
	        out.println("</script>");      
	        out.println("</html>"); 
		}else {
			return true;
		}
	}
	return false;
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:26,代碼來源:LoginInterceptor.java

示例6: aliPayNotifyRes

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * 支付寶移動支付後台通知響應
 * @param request
 * @param response
 * @return
 * @throws ServletException
 * @throws IOException
    */
@RequestMapping(value = "/pay/aliPayNotifyRes.htm")
public void aliPayNotifyRes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String result =  doAliPayRes(request, response);
	if(result != null) {
		_log.info("alipay notify response: {}", result);
		response.setContentType("text/html");
		PrintWriter pw;
		try {
			pw = response.getWriter();
			pw.print(result);

		} catch (IOException e) {
			_log.error("Pay response write exception.", e);
		}
	}

}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:26,代碼來源:Notify4AliPayController.java

示例7: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        // 獲取值
        String orderId = request.getParameter("orderId");

        OrderInfo orderInfo = new OrderInfoServiceImpl().query(orderId);

        OrderToTable toTable = new OrderToTable(orderInfo.getOrderId(), orderInfo.getOrderName(), orderInfo.getOrderPhone()
                , orderInfo.getOrderIDcard(), orderInfo.getArrireDate(), orderInfo.getLeaveDate()
                , new RoomTypeServiceImpl().query(orderInfo.getTypeId().getTypeId()).getTypeId()
                , orderInfo.getCheckNum(), orderInfo.getPrice(), orderInfo.getCheckPrice()
                , orderInfo.getDiscount(), orderInfo.getDiscountReason(), orderInfo.getAddBed()
                , orderInfo.getAddBedPrice(), orderInfo.getOrderMoney(), orderInfo.getOrderState()
                , orderInfo.getRemark(), orderInfo.getOperatorId().getLoginName());

        Gson gson = new Gson();
        out.print(gson.toJson(toTable));
    }
 
開發者ID:inkss,項目名稱:hotelbook-JavaWeb,代碼行數:23,代碼來源:QueryOrderInfoServlet.java

示例8: execute

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String method=retriveMethod(req);
	if(method!=null){
		invokeMethod(method, req, resp);
	}else{
		VelocityContext context = new VelocityContext();
		context.put("contextPath", req.getContextPath());
		String file=req.getParameter("file");
		String project = buildProjectNameFromFile(file);
		if(project!=null){
			context.put("project", project);
		}
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		Template template=ve.getTemplate("html/decisiontree-editor.html","utf-8");
		PrintWriter writer=resp.getWriter();
		template.merge(context, writer);
		writer.close();
	}
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:22,代碼來源:DecisionTreeEditorServletHandler.java

示例9: service

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    log.info("ip[" + req.getRemoteAddr() + "] requestURL[" + req.getRequestURL() + "] Query["
            + req.getQueryString() + "]");

    try {
        flow.execute(getServletContext(), req, resp);
    } catch (Exception e) {
        log.error("flow execution error", e);
        resp.setContentType("text/plane; charset=UTF-8");
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        PrintWriter pw = resp.getWriter();
        pw.println(e.getMessage());
        pw.close();
    }
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:17,代碼來源:DifferenceServlet.java

示例10: doHandleRequest

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected ModelAndView doHandleRequest(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	String lobId=request.getParameter("lobId");
	String xml=lobStoreService.getString(lobId);
	response.setContentType("text/plain; charset=UTF-8");
	response.setHeader("Pragma", "No-cache");
       response.setHeader("Cache-Control", "no-cache");
       response.setDateHeader("Expires", 0);
       PrintWriter writer=response.getWriter();
       xml=(xml==null)?"":xml;
       writer.write(xml);
       writer.flush();
       writer.close();
	return null;
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:17,代碼來源:LoadProcessController.java

示例11: generateMetadataForIdp

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Displays the identity provider metadata.
 * Checks to make sure metadata exists, and if not, generates it first.
 *
 * @param response servlet response
 * @throws IOException the iO exception
 */
@GetMapping(path = SamlIdPConstants.ENDPOINT_IDP_METADATA)
public void generateMetadataForIdp(final HttpServletResponse response) throws IOException {
    final File metadataFile = this.metadataAndCertificatesGenerationService.performGenerationSteps();
    final String contents = FileUtils.readFileToString(metadataFile, StandardCharsets.UTF_8);
    response.setContentType(CONTENT_TYPE);
    response.setStatus(HttpServletResponse.SC_OK);
    try (PrintWriter writer = response.getWriter()) {
        LOGGER.debug("Producing metadata for the response");
        writer.write(contents);
        writer.flush();
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:20,代碼來源:SamlMetadataController.java

示例12: handleRequest

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	StringBuilder result = new StringBuilder();
	ScheduleMachine m = scheduleMachineFactory.newInstance(String.valueOf(System.currentTimeMillis()), "dtstest");
	m.addContext("goto", 2);
	m.addContext("_i", 3);
	m.run();

	response.setContentType("text/html;charset=utf-8");
	PrintWriter out = response.getWriter();
	out.println(result);
	return null;
}
 
開發者ID:alibaba,項目名稱:bulbasaur,代碼行數:14,代碼來源:DTSController.java

示例13: commence

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void commence ( HttpServletRequest request ,
					   HttpServletResponse response ,
					   AuthenticationException authException ) throws IOException {
	response.setHeader( "Content-type" , MediaType.APPLICATION_JSON_UTF8_VALUE );
	response.setCharacterEncoding( StandardCharsets.UTF_8.displayName() );
	try ( PrintWriter out = response.getWriter() ) {
		out.print( JsonUtils.toCustomizationJson( ResponseEntityPro.unauthorized( "未經授權:身份驗證令牌丟失或無效。" ) ) );
	}
}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:11,代碼來源:JwtAuthenticationEntryPoint.java

示例14: attackHandle

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
public void attackHandle ( HttpServletRequest request , HttpServletResponse response , String parameters ) throws
                                                                                                           IOException {
    response.setHeader( "Content-type" , MediaType.APPLICATION_JSON_UTF8_VALUE );
    response.setCharacterEncoding( StandardCharsets.UTF_8.displayName() );
    try ( PrintWriter out = response.getWriter() ) {
        out.print( JsonUtils.toCustomizationJson( ResponseEntityPro.badRequest( "請求內容包含非法字符,原請求內容:\n" + parameters ) ) );
    }
}
 
開發者ID:yujunhao8831,項目名稱:spring-boot-start-current,代碼行數:10,代碼來源:DefaultInjectionAttackHandler.java

示例15: saveManagedEntitiesOrdering

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void saveManagedEntitiesOrdering(HttpServletRequest req, HttpServletResponse resp,
                                         EntitiesService as, ResourceBundle backendMessages,
                                         ResourceBundle messages) throws IOException {
  xLogger.fine("Entering saveManagedEntitiesOrdering");
  String userId = req.getParameter(USERID);
  if (userId == null || userId.isEmpty()) {
    xLogger.severe("Invalid, null or empty userId. {0}", userId);
    return;
  }
  String routeQueryString = req.getParameter("routequerystring");
  if (routeQueryString == null || routeQueryString.isEmpty()) {
    xLogger.severe("Invalid, null or empty routeQueryString. {0}", routeQueryString);
    return;
  }

  String message = null;
  xLogger.fine("userId = {0}", userId);
  xLogger.fine("routeQueryString = {0}", routeQueryString);
  // Get the domain Id
  SecureUserDetails sUser = SecurityMgr.getUserDetails(req.getSession());
  Long domainId = SessionMgr.getCurrentDomain(req.getSession(), sUser.getUsername());

  try {
    as.updateManagedEntitiesOrdering(domainId, userId, routeQueryString);
  } catch (ServiceException e) {
    xLogger.severe("Exception when saving managed entities route for userID {0}", userId);
    message = backendMessages.getString("error") + ": " + e.getMessage();
  }
  String jsonString = null;
  if (message != null && !message.isEmpty()) {
    // There was an error
    jsonString = "{ \"st\" : \"1\", \"msg\" : \"" + message + "\" } ";
    resp.setStatus(500);
  } else {
    // Success
    jsonString = "{ \"st\" : \"0\", \"msg\" : \"\" }";
    resp.setStatus(200);
  }
  resp.setContentType(JsonRestServlet.JSON_UTF8);
  PrintWriter pw = resp.getWriter();
  pw.write(jsonString);
  pw.close();
  xLogger.fine("Exiting saveManagedEntitiesOrdering");
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:45,代碼來源:CreateEntityServlet.java


注:本文中的javax.servlet.http.HttpServletResponse.getWriter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。