HTML 5video标记无法在Tomcat中运行(已编辑)

video无法使用文件的绝对路径和相对路径从Tomcat 7服务器播放:

编辑摘要:改变了相对路径的示例,我将video放在应用程序Root-Folder中(仍然无法解决video错误)。

我们正在构建一个用于本地使用的video查看的小应用程序。 由于HTML-5为video观看提供了巨大的支持,我们选择使用简单的Servlet / JSP编写程序,将其部署在Tomcat 7 Web服务器上

应用程序逻辑如下:

  1. 根路径(绝对路径)设置为tomcat中我的应用程序的根文件夹。
  2. root下面的所有文件和目录都显示在旁边的“go”按钮。
  3. 如果通过单击“开始”选择文件夹中的video文件,则会显示video查看页面。
  4. 使用Expression langauge(EL)将video文件的相对提供给video页面到video标签的源。
  5. video应该从localhost的硬盘播放到所有浏览器端点。

我面临的问题是我的video不是从tomcat服务器播放,而是在浏览器上复制并粘贴到video工作正常的文件时,html的’源’代码相同。 如何使它从tomcat服务器工作?

编辑后:我修改了我的应用程序以调整tomcat myapp的根文件夹中的相对路径,但它仍然无法正常工作。 以下是已编辑的问题。

我的应用程序的屏幕短裤是:


第一阶段:单击链接

第一阶段


第二阶段:选择要浏览的video或文件夹

第二阶段


第三阶段:播放video (这里我收到错误) 第三阶段


服务器在浏览器上呈现以下HTML(从视图源复制):

   Cluster Video App     

Enjoy the Video


当将相同的源复制并粘贴到计算机中任何位置的示例html页面时,video工作正常。 下面的图像certificate了这一点。

预期产出


编辑后:服务器呈现包含video的正确相对路径。 该video尚未正常运行。

    Cluster Video App     

Enjoy the Video

video出现在我的应用程序的根目录中:

Tomcat根视频根

我已将编辑过的程序粘贴在此页面中以供参考。 请纠正我并帮我清除video错误。



程序

包装结构:

包装结构


在web.xml

    <!--  /welcome.do  -->   Controller com.cluster.vapp.controller.ControllerServlet 1    Controller *.do   

控制器Servlet:

  package com.cluster.vapp.controller; import java.io.IOException; import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.cluster.vapp.fileutils.FileUtil; import com.cluster.vapp.fileutils.SearchResult; import com.cluster.vapp.service.VappService; import com.cluster.vapp.service.VappServiceImpl; public class ControllerServlet extends HttpServlet { private static final long serialVersionUID = 1L; private VappService service; public void init() throws ServletException { service = new VappServiceImpl(); } protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); // HttpSession session = request.getSession(); String strServletPath = request.getServletPath(); // debug System.out.println(strServletPath); // end of debug int intServletpath = 0; if (strServletPath.equalsIgnoreCase("/welcome.do")) { intServletpath = 1; } if (strServletPath.equalsIgnoreCase("/verify.do")) { intServletpath = 2; } if (strServletPath.equalsIgnoreCase("/searchRoot.do")) { intServletpath = 3; } switch (intServletpath) { case 1: {// welcome.do RequestDispatcher requestDispatcher = request .getRequestDispatcher("./JSP/welcome.jsp"); requestDispatcher.forward(request, response); break; } case 2: { // verify.do if (service.isVideoFile(request.getParameter("path_name"))) { String strVideoPath = service.findRelative(request .getParameter("path_name")); request.setAttribute("VIDEO_PATH", FileUtil.adjustPathName(strVideoPath)); RequestDispatcher requestDispatcher = request .getRequestDispatcher("./JSP/video.jsp"); requestDispatcher.forward(request, response); } else { List listSearchResults = service .searchDirectory(request.getParameter("path_name")); request.setAttribute("LIST_SEARCH_RESULT", listSearchResults); RequestDispatcher requestDispatcher = request .getRequestDispatcher("./JSP/search.jsp"); requestDispatcher.forward(request, response); } break; } case 3: {// searchRoot.do List listSearchResults = service .searchRootDirectory(); request.setAttribute("LIST_SEARCH_RESULT", listSearchResults); RequestDispatcher requestDispatcher = request .getRequestDispatcher("./JSP/search.jsp"); requestDispatcher.forward(request, response); break; } } } } 

VappServiceImpl.java

 package com.cluster.vapp.service; import java.io.File; import java.util.ArrayList; import java.util.List; import com.cluster.vapp.fileutils.FileUtil; import com.cluster.vapp.fileutils.SearchResult; public class VappServiceImpl implements VappService{ public static final String ROOT_PATH = "F:\\apache-tomcat-7.0.33\\webapps\\balaji\\ROOT-VIDEO"; public static final String BASE_PATH = "F:\\apache-tomcat-7.0.33\\webapps\\balaji"; public List searchRootDirectory() { List listDirectoryNames = FileUtil.fetchFileNames(ROOT_PATH); List listSearchResults = new ArrayList(); for (String dirName : listDirectoryNames) { SearchResult result = new SearchResult(); result.setStrName(dirName); result.setStrPath(ROOT_PATH + "\\" + dirName); listSearchResults.add(result); } return listSearchResults; } public boolean isVideoFile(String pStrPath) { File file = new File(pStrPath); // System.out.println("Is file There: " + file.exists()); if (file.isFile()) return true; else return false; } public List searchDirectory(String pStrPath) { List listDirectoryNames = FileUtil.fetchFileNames(pStrPath); List listSearchResults = new ArrayList(); for (String dirName : listDirectoryNames) { SearchResult result = new SearchResult(); result.setStrName(dirName); result.setStrPath(pStrPath + "\\" + dirName); listSearchResults.add(result); } return listSearchResults; } public String findRelative(String pStrVideoPath){ return FileUtil.findRelativePath(BASE_PATH, pStrVideoPath); } } 

FileUtil.java

 package com.cluster.vapp.fileutils; import java.io.File; import java.util.ArrayList; import java.util.List; import com.cluster.vapp.fileutils.exceptions.InvalidAbsolutePathException; import com.cluster.vapp.fileutils.exceptions.InvalidDirectoryNameException; /** * @author Balaji.KR * * @version 1.0 * * The class Contains methods for various file operations. All methods * present will accept only absolute string path of the source and * destination file structure. * */ public class FileUtil { /** * The Method returns the names of the files as a list, in the path given. * * Note: The path name should be a absolute path, and should be a existing * directory. Any violation will lead to corresponding run-time exception. * * * @param pStrDirectory * Location of the directory where it needs to be searched. * @return List of file names as string existing in the directory. */ public static List fetchFileNames(String pStrDirectory) { List listFileNames = new ArrayList(); File directory = new File(pStrDirectory); if (directory.isAbsolute() == false) { throw new InvalidAbsolutePathException( "Directory Path is not Absolute"); } if ((directory.exists() && directory.isDirectory()) == false) { throw new InvalidDirectoryNameException(); } String[] strFileNames = directory.list(); for (String name : strFileNames) { listFileNames.add(name); } return listFileNames; } public static String adjustPathName(String pStrPath) { StringBuilder sb = new StringBuilder(pStrPath); sb.insert(0, "../"); return sb.toString(); } public static String findRelativePath(String pStrBasePath, String pStrAbsolutePath) { return new File(pStrBasePath).toURI() .relativize(new File(pStrAbsolutePath).toURI()).getPath(); } } 

的welcome.jsp

    Cluster Video App   

Cluster Video Application









Browse Videos


search.jsp的

      Cluster Video App  function submitForm(form){form.submit();}   div.label{font-size: 30px; color: blue; margin: 10px;}    

Click to proceed...

${result.strName}

video.jsp

    Cluster Video App     

Enjoy the Video

这是出于安全原因。 从某些服务器加载的页面无法从本地驱动器加载文件。 将video复制到src / main / webapp / video.m4v。 将JSP更改为:

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>    Cluster Video App    

Enjoy the Video

将文件夹放在WebContent文件夹或webapps文件夹中,然后提供类似./folder1/file.mp4的路径,如果没有WebContent ,则使用eclipse创建一个新项目设置,并使用DynamicWebProject粘贴其中的旅游文件。

我也得到了这个问题,但现在它[求助] ,我正在使用tomcat 8和java 7

怎么样检查video.js它确实有效。 我测试了Apache-Tomcat 8.5。

首先,包括这两行

   

并使用像这样的video标签。