Преобразование страниц JSP в сервлеты - PullRequest
0 голосов
/ 19 сентября 2018

У нас также есть HTML-теги на страницах JSP, поэтому при выполнении jsp он преобразуется в сервлет.Поэтому мой вопрос: что случилось с тегами HTML или где мы можем найти теги HTML в сервлете?

1 Ответ

0 голосов
/ 19 сентября 2018

Каждая страница JSP, идентифицированная с помощью «.jsp» и преобразованная в сервлет с помощью JSP Engine. Некоторые примеры: -

Файл: -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")

Весь HTML-код внутри .jsp переходит в сервисный метод сервлета. Пример выше .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 в сервлет (.java) и файл .class.

Здесь вы можете найти .class сервлет .java (Tomcat Server)./DashboardApp/target/tomcat/work/localEngine/localhost/DashboardApp/org/apache/jsp/WEB_002dINF/view/dashboardApp_jsp.java

...