• jsp脚本和注释


    jsp技术(可以嵌套java代码,也擅长写HTML代码)!

    jsp本质其实就是一个servlet类

    jsp脚本

    <%j ava代码 %>  1)----- 内部的java代码翻译到service方法的内部

    <%=java变量或表达式%> ----- 会被翻译成service方法内部out.print()

    <%!java代码%> ---- 会被翻译成servlet的成员的内容

    jsp注释:

    Html注释:<!--注释内容--> 

    java注释://单行注释  /*多行注释*/

    jsp注释:<%--注释内

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
       <!--这是HTML注释-->
       <%  
           //这是java单行注释
           /*这是java多行注释*/
    	   int i=100; 
    	   System.out.print(i);
       %>
       <%--这jsp注释 --%>
       <%=i %>
       <%! String str="起于凡而非凡"; %>
       <%=str %>
    </body>
    </html>
    

    jsp指令三个:

    page指令:<%@ page 属性名1= "属性值1" 属性名2= "属性值2" ...%>

    include指令:格式:<%@ include file="被包含的文件地址"%>

    taglib指令:格式:<%@ taglib uri="标签库地址" prefix="前缀"%>

    <%@page import="java.util.ArrayList"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" session="false" errorPage="Error.jsp"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
      <%  
           int y=1/0;
    	  /*如果Session为false时则body里面报错,必须重新创建session对象,不是false时默认是true*/
    	  HttpSession session=request.getSession();
    	  session.setAttribute("goods","naiping");
      %>
      <%
      	ArrayList<String> arr=new ArrayList<String>(); 
      %>
    </body>
    </html>
    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
         <%@ include file="header.jsp" %>
       	  这是内容
       	 <%@ include file="footer.jsp" %>
    </body>
    </html>
    

      

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" isErrorPage="true"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    这是一个处理错误页面
    </body>
    </html>
    

      

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    这是尾部
    </body>
    </html>
    

      

      

    容--%>

  • 相关阅读:
    Robotium源码分析之Instrumentation进阶
    路飞学城Python-Day115
    路飞学城Python-Day114
    路飞学城Python-Day113
    【逻辑回归的特征筛选方法】
    路飞学城Python-Day108
    路飞学城Python-Day107
    【算法学习】神经网络
    路飞学城Python-Day100
    路飞学城Python-Day101
  • 原文地址:https://www.cnblogs.com/awdsjk/p/11145990.html
Copyright © 2020-2023  润新知