码迷,mamicode.com
首页 > 其他好文 > 详细

指令实例 page,include, taglib

时间:2020-04-04 11:35:13      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:password   gets   script   rds   control   发放   art   title   pass   

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

标签:password   gets   script   rds   control   发放   art   title   pass   

原文地址:https://www.cnblogs.com/kukudemumubuku/p/12630611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!