Java的Servlet调用服务器上的html文件直接在客户端打开
来源:互联网 发布:java自行车 知乎 编辑:程序博客网 时间:2024/05/22 14:29
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
service(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
service(request, response);
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String file_add = request.getParameter("FileAddress");
OutputStream outStream = response.getOutputStream();
try{
FileInputStream fip = new FileInputStream(file_add);
byte[] buffer = new byte[1024]; // 建立缓冲区
int len;
while ((len = fip.read(buffer)) != -1){
outStream.write(buffer, 0, len);
}
fip.close();
outStream.close();
// 关闭输入流,释放系统资源
}catch(Exception e) {
System.out.println(e.getStackTrace());
}
}
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
service(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
service(request, response);
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String file_add = request.getParameter("FileAddress");
OutputStream outStream = response.getOutputStream();
try{
FileInputStream fip = new FileInputStream(file_add);
byte[] buffer = new byte[1024]; // 建立缓冲区
int len;
while ((len = fip.read(buffer)) != -1){
outStream.write(buffer, 0, len);
}
fip.close();
outStream.close();
// 关闭输入流,释放系统资源
}catch(Exception e) {
System.out.println(e.getStackTrace());
}
}
- Java的Servlet调用服务器上的html文件直接在客户端打开
- html中实现添加水印的功能 / 在jsp页面上直接打开PDF文件
- 记录一下:上传到服务器上的pdf 文件直接下载而非在浏览器里打开
- 在WebSphere服务器上,如何编译JSP文件为Servlet的源文件(java)
- java方法客户端下载服务器上的文件到本地
- java方法客户端下载服务器上的文件到本地
- java方法客户端下载服务器上的文件到本地
- 在文件下载的时候将其保存而不是直接在浏览器上打开!
- 客户端通过 JSON直接调用服务器的函数。
- 如何将存在服务器上的word文件在客户端浏览的时候以html页的形式发送给用户?
- C#直接调用IE打开指定的网页文件
- 能在打开的网页上直接录音吗?
- 在java的WEB项目如何防止浏览器直接打开下载的文件
- 一次在服务器上直接修改项目中*.properties文件导致的BUG
- weblogic服务上传word等文件直接打开问题解决 博客分类: web应用服务器 在weblogic上发布的web项目,测试中发现出现当上传word、excel、pdf等文件在下载的时候出现
- 从服务器上读取客户端文件,把服务器上的的文件写入客户端
- 客户端打开服务器的word
- 在android手机上打开html文件
- 线性表的简单实现
- log日志框架和LocationAwareLogger问题
- UITableView for Android
- (转载)java synchronized详解
- 【转】Tapestry5和Eclipse的整合
- Java的Servlet调用服务器上的html文件直接在客户端打开
- Kii Cloud后端特性分析
- SideNavigation—仿facebook菜单效果
- JAVA直接本地HTML和TXT文件。
- java中hashcode和equal详解
- JAVA面向对象程序设计——类的基本形式(封装)
- JDK中的URLConnection参数详解
- java读取文本文件数据
- java复习(set 、list、map)