您的位置:首页 > Web前端 > JavaScript

JSP学习笔记(一)

2015-08-15 09:59 696 查看
注释:

1.单行注释<!-- -->或者//

<%@ page language="java" import="java.util.*" contentType="text/html; utf-8""%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'HelloWorld.jsp' starting page</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">
-->
<title>
Hello,World
</title>
</head>

<body>
<!-- 打印Hello World -->
<%
out.print("Hello,world!");
%>
</body>
</html>


2.多行注释<% %>

<%@ page language="java" import="java.util.*" contentType="text/html; utf-8""%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'HelloWorld.jsp' starting page</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">
-->
<title>
Hello,World
</title>
</head>

<body>
<%--
打印
Hello,world!
--%>
<%
out.print("Hello,world!");
%>
</body>
</html>


JSP脚本元素

1.JSP声明<%! %>

2.JSP表达式<%= %>

3.JSP Scriptlets<% %>

<%@ page language="java" import="java.util.*" contentType="text/html; utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'HelloWorld.jsp' starting page</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">
-->
<title>
JSP脚本元素
</title>
</head>

<body>
<%!
int num1=1;
int num2=2;
int num3;
int add(int num1,int num2)
{
return num1+num2;
}
%>
<%
num3=num1+num2;
%>
num1+num2=<%=add(num1,num2) %>
<br>
num3=<% out.println(num3);%>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: