Java 在 HTML 中包含 JSP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20991373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Including JSP in HTML
提问by user3148359
I'm developing a web page, in that page at bottom I have to upload a file. I have code for upload, but that is in JSP. How I can include that JSP in my HTML page?
我正在开发一个网页,在底部的那个页面中,我必须上传一个文件。我有上传代码,但那是在 JSP 中。如何在我的 HTML 页面中包含该 JSP?
index.jsp
索引.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>
回答by developerwjk
You can include an html file in a jsp file but cannot include a jsp file in a html file because html files are not parsed on the server-side (so how will the server know to do the include?) and jsp are (assuming you are using a servlet-container).
您可以在 jsp 文件中包含一个 html 文件,但不能在 html 文件中包含一个 jsp 文件,因为 html 文件不在服务器端解析(那么服务器如何知道执行包含?)而 jsp 是(假设您正在使用 servlet 容器)。
Make the main file a JSP, put the snippet in an html file, then include in your DIV by using
将主文件设为 JSP,将代码片段放入 html 文件中,然后使用以下命令将其包含在 DIV 中
<div>
<jsp:include page="snippet.html" />
</div>