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>
容--%>