在HTML中包含JSP

时间:2014-01-08 09:19:03

标签: java html jsp

我正在开发一个网页,在该页面底部我必须上传一个文件。我有上传代码,但是在JSP中。我如何在我的HTML页面中包含该JSP?

的index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
     pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>File Upload Example in JSP and Servlet - Java web application</title>
</head>

<body> 
    <div>
        <h3> Choose File to Upload in Server </h3>
        <form action="UploadServlet" method="post" enctype="multipart/form-data">
            <input type="file" name="file" />
            <input type="submit" value="upload" />
        </form>          
    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:-1)

你可以在一个jsp文件中包含一个html文件,但不能在html文件中包含一个jsp文件,因为html文件在服务器端没有被解析(那么服务器如何知道做包含?)和jsp是(假设您使用的是servlet容器)。

将主文件设为JSP,将代码段放入html文件中,然后使用

包含在DIV中
<div>
   <jsp:include page="snippet.html" />
</div>
相关问题