Jsp
1、指令:
page | 常有:language(指定语言)、import、contenType(指定编码) |
---|---|
include | 嵌入其他jsp页面 |
taglib | 引入自定义的标签库 |
2、声明和表达式:
声明:<%! >
表达式:<%= >
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!
String s="张晓明";
int add(int x,int y){
return x+y;
}
%>
大家好,我叫<%=s %>,今年<%=add(10, 8) %>岁
</body>
</html>
3、内置对象:
常用:
out | 在页面输出打印内容 |
---|---|
request | 获取请求的对象 |
response | 对请求的回应操作 |
session | 会话 |
application | 全局对象,整个项目运行期间都有效 |
- 常用方法:
out | print(),newLine(),close() |
---|---|
request | getParameter(String strTextName), getServletPath() 获取客户提交信息的页面 |
response | setContentType(String s),改变contentType的属性值,sendRedirect(index.jsp);重定向 |
– | – |
session | getId()获取session对象的id, setAttribute(String key,Object obj),getAttribute(String key) |
application | setAttribute(String key,Object obj),getAttribute(String key) |
– | – |