1. 程式人生 > >JSP技術

JSP技術

war set log jsp2 編譯 http sta pri epo

一.jsp腳本和註釋

  • jsp腳本:

  1)  <%java 代碼%>----------內部的java代碼翻譯到service 方法的內部

  2)  <%=java變量或表達式%>-------會被翻譯成service方法內部的out.print()

  3)  <%java 代碼%>會被翻譯成servlet的成員的內容

  • jsp註釋:

  1)  Html註釋:  <!--註釋內容-->

  2)  java註釋:  //單行註釋 /*多行註釋*/ 

  3)  jsp註釋:  <%--註釋內容--%>

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.werner</groupId> 5 <artifactId>jsp2</artifactId> 6 <packaging>war</packaging> 7 <version>1.0-SNAPSHOT</version> 8
<name>jsp2 Maven Webapp</name> 9 <url>http://maven.apache.org</url> 10 <dependencies> 11 <dependency> 12 <groupId>junit</groupId> 13 <artifactId>junit</artifactId> 14 <version>3.8.1</version> 15 <scope>test</scope> 16
</dependency> 17 <dependency> 18 <groupId>javax.servlet.jsp</groupId> 19 <artifactId>javax.servlet.jsp-api</artifactId> 20 <version>2.3.1</version> 21 <scope>provided</scope> 22 </dependency> 23 <dependency> 24 <groupId>javax.servlet</groupId> 25 <artifactId>javax.servlet-api</artifactId> 26 <version>3.1.0</version> 27 <scope>provided</scope> 28 </dependency> 29 <!-- https://mvnrepository.com/artifact/javax.el/javax.el-api --> 30 <dependency> 31 <groupId>javax.el</groupId> 32 <artifactId>javax.el-api</artifactId> 33 <version>3.0.0</version> 34 </dependency> 35 <!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl --> 36 <dependency> 37 <groupId>javax.servlet.jsp.jstl</groupId> 38 <artifactId>jstl</artifactId> 39 <version>1.2</version> 40 </dependency> 41 <!-- https://mvnrepository.com/artifact/taglibs/standard --> 42 <dependency> 43 <groupId>taglibs</groupId> 44 <artifactId>standard</artifactId> 45 <version>1.1.2</version> 46 </dependency> 47 </dependencies> 48 <build> 49 <finalName>jsp2</finalName> 50 </build> 51 </project>

<%@page language="java" contentType="text/html;UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.util.*" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
xxxxxxxxx
<!--html的註釋-->
<%----%> jsp註釋
<% int i=0;
System.out.println(i);

%>
<%=i %>
<%=1+1 %>
<%!
String str ="nihao CHIAN";
%>
<%=str%>
</body>
</html>

``````````````````````````````````````````````````````````````````````````````````````````````````````````


xxxxxxxxx jsp註釋 0 2 nihao CHIAN


  • jsp運行原理

  JSP在第一次被訪問時會被WEB容器翻譯成servlet,在執行過程:

  第一次訪問----->hellosServlet.java---->helloServlet_jsp.servlet----->編譯運行PS

:被翻譯後的servlet在Tomcat 的work目錄中可以找到

  • jap指令(3個)

  jsp的指令是指導jsp翻譯和運行的命令,jsp包括三大指令:

  

JSP技術