要实现将实际的HTML打印出来而不是重定向到Java servlet上的网页,可以采用以下方法:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Print HTML</title></head>");
out.println("<body>");
out.println("<h1>This is the actual HTML content</h1>");
out.println("<p>Hello, World!</p>");
out.println("</body></html>");
out.close();
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Print HTML</title>
</head>
<body>
<h1>This is the actual HTML content</h1>
<p>Hello, World!</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Print HTML</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h1>This is the actual HTML content</h1>
<p>{{ message }}</p>
</div>
<script>
new Vue({
el: '#app',
data: {
message: 'Hello, World!'
}
});
</script>
</body>
</html>
以上是三种常见的方法,根据具体需求和开发环境选择适合的方式来打印实际的HTML内容。
领取专属 10元无门槛券
手把手带您无忧上云