本文整理汇总了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();
}
示例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();
}
}
示例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());
}
示例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");
}
}
示例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;
}
示例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);
}
}
}
示例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));
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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( "未经授权:身份验证令牌丢失或无效。" ) ) );
}
}
示例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 ) ) );
}
}
示例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");
}