指令实例 page,include, taglib
Posted kukudemumubuku
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了指令实例 page,include, taglib相关的知识,希望对你有一定的参考价值。
1:page
引入one包中的类User
<%@ page language="java" import="java.util.*,one.User" pageEncoding="UTF-8"%> <% 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>My JSP ‘page.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"> --> </head> <body> <% //引入User类 在page指令内引入one.User类 User user=new User(); %> </body> </html>
其中User类:
package one; public class User { private String username; private String 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个有参的构造方法 public User(String username,String password){ this.username=username; this.username=password; } //无参的构造发放 public User(){ } //验证用户名和密码 public boolean checkUser(){ if(("zhangsan".equals(username))&&("pass123".equals(password))){ return true; }else{ return false; } } }
2:include
主:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP ‘include.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">
-->
</head>
<body>
<h1>主页面</h1>
<%@include file="text.jsp" %>
</body>
</html>
被引入:
。。。 <body> This is my JSP page. <br> </body> 。。。
*注意:引入与被引入不能有相同的定义 <%string%>,<base>等不然会报错
3:taglib
暂且用不上,可以参考上一个博客:https://www.cnblogs.com/kukudemumubuku/p/12625909.html
以上是关于指令实例 page,include, taglib的主要内容,如果未能解决你的问题,请参考以下文章