web容器會把jsp最終轉化爲servlet
類,jsp中的如下標記將進行以下轉化:html
<% ... %>
:代碼出如今方法內<%! ... %>
:代碼直接出如今類內(不在類內方法中)<%= ... %>
:至關於<% out.print(...) %>
<%@ ... %>
:指令
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page import="servlet.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Test</title> </head> <body> <h1>tests</h1> <h2> <% String name = request.getAttribute("name").toString(); out.print(name); %> <%! int count=0 %> <%= name %> </h2> </body> </html>