我们在JSP页面中也有HTML标记,因此在执行jsp时,它将转换为Servlet。所以我的问题是HTML标记发生了什么,或者我们在servlet中可以找到HTML标记?
答案 0 :(得分:1)
每个由“ .jsp”标识并由JSP Engine转换为Servlet的JSP页面。一些示例为:-
文件:-dashboardApp.jsp
<!DOCTYPE html>
<html>
<head>
<title>Dashboard App</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="appResources/images/favicon.ico" type="image/x-icon" />
<!-- jquery library -->
<script type="text/javascript" src="appResources/jquery/jquery.min_3.3.1.js"></script>
</head>
<body ng-app="dashboardApp">
<!-- ${userId} ${userName} -->
<input type="hidden" id="userId" name="userId" value="${userId}" />
<input type="hidden" id="userName" name="userName" value="${userName}" />
</body>
</html>
文件:-dashboardApp_jsp.java(通过添加文件名+“ _ jsp.java”创建的相同文件)
.jsp中的所有html代码都进入servlet的服务方法。上述.jsp文件的示例
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspWriter out = out = pageContext.getOut();
out.write("<!DOCTYPE html>\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write(" <title>Dashboard App</title>\r\n");
out.write(" <meta charset=\"utf-8\">\r\n");
out.write(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\r\n");
out.write(" <link rel=\"shortcut icon\" href=\"appResources/images/favicon.ico\" type=\"image/x-icon\" />\r\n");
out.write(" \r\n");
out.write(" <!-- jquery library -->\r\n");
out.write(" <script type=\"text/javascript\" src=\"appResources/jquery/jquery.min_3.3.1.js\"></script> \r\n");
out.write("<body ng-app=\"dashboardApp\">\r\n");
out.write(" <input type=\"hidden\" id=\"userId\" name=\"userId\" value=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${userId}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write("\" />\r\n");
out.write(" <input type=\"hidden\" id=\"userName\" name=\"userName\" value=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${userName}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
out.write("\" /> \r\n");
out.write("</body>\r\n");
out.write("</html>");
}
JSP引擎将.jsp文件转换为servlet(.java)和.class文件。
在这里您可以找到.class servlet .java(Tomcat服务器)。 /DashboardApp/target/tomcat/work/localEngine/localhost/DashboardApp/org/apache/jsp/WEB_002dINF/view/dashboardApp_jsp.java