相关疑难解决方法(0)

在Java Web应用程序中从应用程序服务器外部提供静态数据的最简单方法

我有一个在Tomcat上运行的Java Web应用程序.我想加载静态图像,这些图像将在Web UI和应用程序生成的PDF文件中显示.此外,还将通过Web UI上传添加和保存新图像.

通过将静态数据存储在Web容器中但从Web容器外部存储和加载它们来解决这个问题并不是一个问题.

我不想在此时使用像Apache这样的单独的Web服务器来提供静态数据.我也不喜欢将图像以二进制形式存储在数据库中.

我已经看到一些建议,比如将图像目录作为指向Web容器外部目录的符号链接,但这种方法是否适用于Windows和*nix环境?

有人建议编写一个过滤器或servlet来处理图像服务,但这些建议非常模糊和高级别,没有指向如何实现这一目标的更详细信息.

tomcat servlets static-content java-ee

129
推荐指数
5
解决办法
14万
查看次数

视频使用HTML 5和servlet

下面给出的代码用于视频流.这对于IE9和Firefox来说很不错,但Chrome和Mac Safari不行.

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class VideoStreamServlet
 */

public class VideoStreamServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public VideoStreamServlet() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String range = request.getHeader("range");
        String browser = request.getHeader("User-Agent");
        System.out.println(browser);
        if(browser.indexOf("Firefox") != …
Run Code Online (Sandbox Code Playgroud)

java video html5 servlets java-ee

5
推荐指数
1
解决办法
2万
查看次数

JSF播放视频文件

我想从我的Web应用程序播放视频文件。我使用JSF。我想知道如何在客户端系统中安装的任何视频播放器的帮助下打开视频文件。我知道如何以相同方式打开pdf文件。但是我想知道如何打开视频文件。

video jsf desktop-application

3
推荐指数
1
解决办法
6590
查看次数

如何在JSP文件中编写文件下载到响应

当我尝试从响应对象获取ServletOutputStream对象时,我收到了java.lang.IllegalStateException.以下是我的代码:

<%@ page import="java.util.*,java.io.*"%>             

<%
try {
    System.out.print("request came");
    File f = new File ("E:/dd.txt");

    String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
    InputStream in = new FileInputStream(f);

    ServletOutputStream outs = response.getOutputStream();

    response.setContentType ("application/txt");
    response.setHeader ("Content-Disposition", "attachment; filename="+f.getName()+"");
    int bit = 256;
    int i = 0;
    try {
        while ((bit) >= 0) {
            bit = in.read();
            outs.write(bit);
        }
    } catch (IOException ioe) {
        ioe.printStackTrace(System.out);
    }
    outs.flush();
    outs.close();
    in.close();         
} catch (Exception ioe) {
    ioe.printStackTrace(System.out);
}
%>
Run Code Online (Sandbox Code Playgroud)

以下是堆栈跟踪:

java.lang.IllegalStateException
   at org.apache.jasper.runtime.ServletResponseWrapperInclude.getOutputStream(ServletResponseWrapperInclude.java:63)
   at org.apache.jsp.html.portlet.vitage.custom.QUADWAVE.Procfiledownloadess1_005f36901_005f48.filedownload.downloadscreen_jsp._jspService(downloadscreen_jsp.java:5 …
Run Code Online (Sandbox Code Playgroud)

jsp download

2
推荐指数
1
解决办法
1万
查看次数