高手略过
最近在学习jsp的用法,写下来方便大家查阅
本章节写了page的用法和基本jsp基础语法,以例子程序和注释的方式写一下,可以直接copy运行
顺便提一下jsp的运行机制:
<!-- page的用法-->
<!-- language设置本页的页面语言java,现在只支持java -->
<%@ page language="java"%>
<!-- import指定导入的java包 -->
<%@ page import="java.util.*"%>
<%-- 设置页面编码方式utf-8 --%>
<%@ page pageEncoding="utf-8"%>
<%--页面能否使用session对象 --%>
<%@ page session = "false"%>
<!-- buffer指定输出流有没有缓冲区 none的话是没有 -->
<%@ page buffer="40kb" %>
<!--是否自动输出,设置为true时,缓冲区满时自动输出,false则是缓冲区满时,将会产生异常 -->
<%@ page autoflush = "false" %>
<!-- isThreadSafe 用来指定jsp支持多线程使用 -->
<%@ page isThreadSafe = "true"%>
<!-- contentType 用来指定jsp文件的MIME格式,以及网页编码格式 -->
<%@ page contentType="text/html;charset=gb2312" %>
<!-- isELIgnored指定文件是否支持EL表达式 -->
<%@ page isELIgnored="true" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>jsp 基本的内容学习</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 声明a为全局变量,每个使用这个页面都可以使用这个变量-->
<% int a = 1; %>
<!--scriptlet脚本就是jsp的代码部分 -->
<% String str = "Hello";%>
<% String str1 ="juchaochao"; %>
<% out.println("a="+a);
a++;
%>
<% Date now = new Date(); %>
<!-- jsp中的输出方式,有一下两种 -->
<%out.println(now); %>
<%= str%>
<%= str1%>
<% out.println(str1); %>
</body>
</html>