本文整理汇总了Java中javax.servlet.http.HttpServletResponse.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.setContentType方法的具体用法?Java HttpServletResponse.setContentType怎么用?Java HttpServletResponse.setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.setContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: downloadSignedFile
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "/download", method = RequestMethod.GET)
public String downloadSignedFile(@ModelAttribute("signedDocument") InMemoryDocument signedDocument, HttpServletResponse response) {
try {
MimeType mimeType = signedDocument.getMimeType();
if (mimeType != null) {
response.setContentType(mimeType.getMimeTypeString());
}
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Content-Disposition", "attachment; filename=\"" + signedDocument.getName() + "\"");
Utils.copy(new ByteArrayInputStream(signedDocument.getBytes()), response.getOutputStream());
} catch (Exception e) {
logger.error("An error occured while pushing file in response : " + e.getMessage(), e);
}
return null;
}
示例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());
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/decisiontable-editor.html","utf-8");
PrintWriter writer=resp.getWriter();
template.merge(context, writer);
writer.close();
}
}
示例3: code
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* 生成代码
*/
@RequestMapping("/code")
@RequiresPermissions("sys:generator:code")
public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{
String[] tableNames = new String[]{};
//获取表名,不进行xss过滤
HttpServletRequest orgRequest = XssHttpServletRequestWrapper.getOrgRequest(request);
String tables = orgRequest.getParameter("tables");
tableNames = JSON.parseArray(tables).toArray(tableNames);
byte[] data = sysGeneratorService.generatorCode(tableNames);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"renren.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
示例4: createSuccessResponse
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public static String createSuccessResponse(Integer httpCode, Object result, SerializerFeature serializerFeature, SerializeFilter filter, HttpServletResponse response){
PrintWriter printWriter = null;
String jsonString = "";
try {
response.setCharacterEncoding(RESPONSE_CHARACTERENCODING);
response.setContentType(RESPONSE_CONTENTTYPE);
response.setStatus(httpCode);
printWriter = response.getWriter();
if(null != result){
if(null!=filter){
jsonString = JSONObject.toJSONString(result,filter,serializerFeature);
}else{
// jsonString = JSONObject.toJSONString(result, serializerFeature);
jsonString = JSONObject.toJSONStringWithDateFormat(result,"yyyy-MM-dd HH:ss:mm",serializerFeature);
}
printWriter.write(jsonString);
}
printWriter.flush();
} catch (Exception e) {
log.error("createResponse failed", e);
} finally {
if(null!=printWriter)printWriter.close();
}
return jsonString;
}
示例5: getText1
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping("/text1")
public void getText1(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
try {
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write("hello");
} catch (IOException e) {
logger.error("getText1 error:", e);
}
}
示例6: doPost
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("DISCONNECT PAIR SERVLET");
String pairId=request.getParameter("pairId");
// String nextPage=request.getParameter("jsp");
int id=Integer.parseInt(pairId);
DataAccess da = new DataAccess();
boolean res=true;
RequestDispatcher req = null;
response.setContentType("text/html");
res = da.disconnectPair(id);
try {
da.closeConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(res){
// response.getWriter().append("Disconnect Pair Successfull");
response.getWriter().append(""+id);
//req = request.getRequestDispatcher(nextPage);
}
else
//response.getWriter().append("Disconnect Pair Is Failure");
req.forward(request, response);
}
示例7: doGet
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Method declaration
*
*
* @param request
* @param response
*
* @throws IOException
* @throws ServletException
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String query = request.getQueryString();
if ((query == null) || (query.length() == 0)) {
response.setContentType("text/html");
// [email protected] 20020130 - patch 1.7.0 by fredt
// to avoid caching on the browser
response.setHeader("Pragma", "no-cache");
PrintWriter out = response.getWriter();
out.println(
"<html><head><title>HSQL Database Engine Servlet</title>");
out.println("</head><body><h1>HSQL Database Engine Servlet</h1>");
out.println("The servlet is running.<p>");
if (errorStr == null) {
out.println("The database is also running.<p>");
out.println("Database name: " + dbType + dbPath + "<p>");
out.println("Queries processed: " + iQueries + "<p>");
} else {
out.println("<h2>The database is not running!</h2>");
out.println("The error message is:<p>");
out.println(errorStr);
}
out.println("</body></html>");
}
}
示例8: doGet
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
resp.getWriter().print("envEntry1: " + envEntry1);
resp.getWriter().print(" envEntry2: " + envEntry2);
resp.getWriter().print(" envEntry3: " + envEntry3);
resp.getWriter().print(" envEntry4: " + envEntry4);
resp.getWriter().print(" envEntry5: " + envEntry5);
resp.getWriter().print(" envEntry6: " + envEntry6);
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:12,代码来源:TesterServletWithAnnotations.java
示例9: processPendingResponses
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
synchronized void processPendingResponses(HttpServletRequest req, HttpServletResponse resp) throws IOException {
JSONArray responses = new JSONArray();
JSONStreamAware pendingResponse;
while ((pendingResponse = pendingResponses.poll()) != null) {
responses.add(pendingResponse);
}
if (responses.size() > 0) {
JSONObject combinedResponse = new JSONObject();
combinedResponse.put("responses", responses);
if (asyncContext != null) {
asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
try (Writer writer = asyncContext.getResponse().getWriter()) {
combinedResponse.writeJSONString(writer);
}
asyncContext.complete();
asyncContext = req.startAsync();
asyncContext.addListener(new UserAsyncListener());
asyncContext.setTimeout(5000);
} else {
resp.setContentType("text/plain; charset=UTF-8");
try (Writer writer = resp.getWriter()) {
combinedResponse.writeJSONString(writer);
}
}
} else {
if (asyncContext != null) {
asyncContext.getResponse().setContentType("text/plain; charset=UTF-8");
try (Writer writer = asyncContext.getResponse().getWriter()) {
JSON.emptyJSON.writeJSONString(writer);
}
asyncContext.complete();
}
asyncContext = req.startAsync();
asyncContext.addListener(new UserAsyncListener());
asyncContext.setTimeout(5000);
}
}
示例10: processRequest
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Processes requests for both HTTP <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 {
response.setContentType("text/html;charset=UTF-8");
DAOTipoMoeda daoTipoMoeda = null;
TipoMoeda tipoMoeda = null;
RequestDispatcher view = null;
String msg = null;
String tipoMsg = "success";
try {
daoTipoMoeda = new DAOTipoMoeda();
tipoMoeda = new TipoMoeda();
tipoMoeda.setNome(request.getParameter("txtNome"));
tipoMoeda.setSimbolo(request.getParameter("txtSimbolo"));
ArrayList<TipoMoeda> lista = daoTipoMoeda.consultar(tipoMoeda);
request.setAttribute("al", lista);
} catch (Exception exception) {
tipoMsg = "danger";
msg = exception.getMessage();
} finally {
view = request.getRequestDispatcher("/pages/tipoMoedaConsultar.jsp");
request.setAttribute("mensagem", msg);
request.setAttribute("tipoMsg", tipoMsg);
view.forward(request, response);
}
}
示例11: onLogoutSuccess
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
Map<String, String> result = new HashMap<>();
result.put( "result", "success" );
response.setContentType("application/json");
response.getWriter().write( objectMapper.writeValueAsString( result ) );
response.setStatus(HttpServletResponse.SC_OK);
}
示例12: writeAJAXResponse
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
protected void writeAJAXResponse(HttpServletResponse response, String output) throws IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
if (output.length() > 0) {
out.println(output);
}
out.flush();
out.close();
}
示例13: processRequest
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Processes requests for both HTTP
* <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 {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
if(sc==null)
{
sc = getServletConfig();
if(sc!=null) init(sc);
}
Map<String, String> __params = new HashMap<String, String>();
Enumeration __e = request.getParameterNames();
while (__e.hasMoreElements()) {
String tField = __e.nextElement().toString();
__params.put(tField, request.getParameter(tField));
}
__params.put("contextpath", request.getContextPath());
String __result=getResponce(__params);
out.println(__result);
} finally {
out.flush();
out.close();
}
}
示例14: wapPay
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Wap支付
* https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.dfHHR3&
* treeId=203&articleId=105285&docType=1
*
* @throws AlipayApiException
* @throws IOException
*/
public static void wapPay(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl,
String notifyUrl) throws AlipayApiException, IOException {
String form = wapPayToString(response, model, returnUrl, notifyUrl);
HttpServletResponse httpResponse = response;
httpResponse.setContentType("text/html;charset=" + AliPayConfig.build().getCharset());
httpResponse.getWriter().write(form);// 直接将完整的表单html输出到页面
httpResponse.getWriter().flush();
}
示例15: ajaxPolling
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Ajax轮询
* @param response HttpServletResponse
* @param requestTime 开始请求时间
* @throws Exception
*/
@RequestMapping(value="/ajax/polling", method= RequestMethod.GET)
public void ajaxPolling(HttpServletResponse response,long requestTime) throws Exception{
response.setContentType("text/html;charset=utf-8");
PrintWriter writer = response.getWriter();
Thread.sleep(new Random().nextInt(1000)); //模拟业务处理时间
int num = new Random().nextInt(100); //模拟查询到的数据,查到就返回
long responseTime = System.currentTimeMillis();
if(num >10 && num <50){ //有数据变化
writer.print(String.format("response time: %s, request time: %s, result: %d", responseTime,requestTime,num));
}else{ //无数据变化
writer.print(String.format("response time: %s, request time: %s, result: %s", responseTime,requestTime,"无数据变化"));
}
}