Java Web:JSP

web容器会把jsp最终转化为servlet类,jsp中的以下标记将进行如下转化:

  • <% ... %>:代码出现在方法内
  • <%! ... %>:代码直接出现在类内(不在类内方法中)
  • <%= ... %>:相当于<% 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>
posted @ 2019-01-15 14:06  xuejianbest  阅读(89)  评论(0编辑  收藏  举报