一、JSP注释:
1.客户端中的可见注释
<!-- this is JSP comments-->
<!—today is <%=new java.util.date().toString() %> -->
注释中显示系统时间
2.客户端中不可见的注释
<%--
This is JSP comments.
--%>
3.JSP的代码段注释
<%
//String str=”hello world”;
%>
二、JSP编译指令
1.编译指令page
在page中加入导入java类的指令,并body中输入一下代码:
运行之后无报错
2.编译指令include
在include.jsp的body中输入:
.
header.html:
.
footer.jsp
运行结果:
注:include所包含的页面最终被转化成一个servlet,而且同一个变量不能被重复声明
三、动作指令
1.JSP动作指令forward
Index.jsp:
.
login.jsp:
.
运行结果:
注:forward指令下面的内容不会被输出
2.JSP动作指令include
index.jsp:
.
header.html:
.
body.jsp:
运行结果:
2.JSP动作指令useBean
1.UserEntity.java:
package com.jikexueyuan.entity;
import java.io.Serializable;
public class UserEntity implements Serializable {
private String userName;
private String password;
public UserEntity(String userName, String password) {
super();
this.userName = userName;
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
2.register.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>录入注册信息</title>
</head>
<body>
<form action="do_register.jsp" method="post">
用户名:<input type="text" name="userName"/>
密码:<input type"password" name="password"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
3.do_register.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>注册信息处理</title>
</head>
<body>
<jsp:useBean id="user" class="com.jikexueyuan.entity.UserEntity"></jsp:useBean>
<jsp:setProperty property="userName" name="user"/>
<jsp:setProperty property="password" name="user"/>
<%
String userName=request.getParameter("userName");
String password=request.getParameter("password");
out.println(userName);
out.println("<br/>");
out.println(password);
%>
<br/>
<jsp:getProperty property="userName" name="user"/>
<jsp:getProperty property="password" name="user"/>
</body>
</html>
注:do_register的useBean方法有个bug~不晓得哪里出问题。
bug:
求晓得的大牛帮忙答复一下