• 首页|
  • php.cn
    search
    logo
    • Community
      • Articles
      • Topics
      • Q&A
    • Learn
      • Course
      • Programming Dictionary
    • Tools Library
      • Development tools
      • Website Source Code
      • PHP Libraries
      • JS special effects
      • Website Materials
      • Extension plug-ins
    • AI Tools
    • Leisure
      • Game Download
      • Game Tutorials
    Log in
    logo
    简体中文zh-cnEnglishen繁体中文zh-tw日本語ja한국어koMelayumsFrançaisfrDeutschde
    HomeDatabaseMysql Tutorial使用JavaBean创建您的网上日历本_MySQL

    使用JavaBean创建您的网上日历本_MySQL

    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
    Jun 01, 2016 pm 02:07 PM
    usecreatecalendar



    有的朋友曾经说过,如果有一个网上的日记本,或者一个网上的万年历能提醒自己到时去干什么事情就好了。其实呀,这样的日历本您自己也能做一个。不信你看下面的例子:

    〈HTML〉
    〈HEAD〉
    〈TITLE〉万年历记事本〈/TITLE〉
    〈/HEAD〉
    〈BODY BGCOLOR ="white"〉
    //设置页面脚本语言是java,导入HtmlCalendarNotePad类,HtmlCalendarNotePad在后面将会讲到
    〈%@ page language="java" import="HtmlCalendarNotePad" %〉

    //定义一个JavaBean,取其id为HtmlCal
    〈jsp:useBean id="HtmlCal" scope="session" "HtmlCalendarNotePad" /〉
    〈%
    // 设置参数,取所需的月份为3月,因为未设定年份,故默认为本年。
    HtmlCal.setMonth(3);
    //设置动作,3月24日时,去天极网,在新窗口打开(也可以以其他的方式打开)
    HtmlCal.setAction(24,"http://www.yesky.com/","_blank");
    %〉
    〈TABLE WIDTH=300〉
    〈TR〉〈TD NOWRAP〉
    〈%=HtmlCal.getHtml()%〉 //以表格的形式输出一个月的月历
    〈/TD〉〈/TR〉
    〈/TABLE〉
    〈/BODY〉
    〈/HTML〉

      你将看到如下输出结果

    Mon Tue Wed Thu Fri Sat Sun
    1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31

      这不就跟日历本上一样了吗,不过它比日历本好在,有预设好的链接可以提醒您到时去某个站点,或 执行某个javascript函数,这样不又起了一个记事本的作用了吗?当然了,你也可以自己添加一些功能,使 它变得更加强大,比如添加一个表单,可以让用户填写日记发送到您的系统的数据库中等等。为了完成这个目的, 先让我们来看一看JavaBean程序是如何书写的。

    JavaBean程序分析
    我想把HtmlCalendarNotePad中的主要方法介绍一些,相信会大家有所帮助

    public void setYear(int year) //设置年份 。默认值为当前的年份
    public int getYear() //获得年份 。默认值为当前的年份

    "一月", "二月", "三月", "四月", "五月", "六月",
    "七月", "八月", "九月", "十月", "十一月", "十二月"
    };

    private int year;
    private int month;
    private int style;
    private String sFont;
    private Locale loc;
    private static String NEWLINE = "\n";

     

    public HtmlCalendarNotePad () //构造函数

    {

    sFont = null;

    GregorianCalendar gCalendar = new GregorianCalendar(); //取得当前的日历(格里高里历)

    config = new Hashtable(); //创建新的哈希表储存配置信息

    NEWLINE = System.getProperty("line.separator");

    style = 2; //设置每星期是以星期日为第一天
    month = gCalendar.get(2); //取得月份

    year = gCalendar.get(1); //取的年份

    loc = Locale.PRC; //设置国家名,默认为中华人民共和国

    }

     

    private String formatObject(String s, Object obj)

    {

    String s1 = "";

    if(obj != null)

    s1 = String.valueOf(String.valueOf(obj));

    if(s == null)

    return s1;

    else

    return s + s1 + "〈/font〉";

    }

     

    private int getDay(Calendar calendar) //取得某日在日历中的位置

    {

    if(style == 2)

    return calendar.get(7) - 1;

    else

    return (calendar.get(7) + 5) % 7;

    }

     

    public String getHtml()

    {

    GregorianCalendar gCalendar = new GregorianCalendar(year, month - 1, 1);

    GregorianCalendar gCalendar1 = new GregorianCalendar(2001, 3, 24);

    SimpleDateFormat simpledateformat = new SimpleDateFormat("EEE", loc);

    //设置缩写格式,EEE是星期的缩写,如 Sun, 若EEEE则为Sunday。

    int i = month - 1;

    int j = 0;

    StringBuffer stringbuffer = new StringBuffer(""); //创建新的字符串缓冲区

    stringbuffer.append("〈table〉〈tr〉\n"); //在stringbuffer上添加〈table〉〈tr〉,为创建表格作准备

    if(style == 2) //见上解释

    {

    stringbuffer.append("〈th align=right〉" + formatObject(sFont, simpledateformat.format(gCalendar1.getTime())) + "〈/th〉\n");

    gCalendar1.add(5, 1);

    for(int k = 1; k 〈 7; k++)

    {

    stringbuffer.append("〈th align=right〉" + formatObject(sFont, simpledateformat.format(gCalendar1.getTime())) + "〈/th〉\n");

    gCalendar1.add(5, 1);

    }

     

    }

    else

    {

    gCalendar1.add(5, 1);

    stringbuffer.append("〈th align=right〉" + formatObject(sFont, simpledateformat.format(gCalendar1.getTime())) + "〈/th〉\n");

    for(int l = 2; l 〈 8; l++)

    {

    gCalendar1.add(5, 1);

    stringbuffer.append("〈th align=right〉" + formatObject(sFont, simpledateformat.format(gCalendar1.getTime())) + "〈/th〉\n");

    }

     

    }

    stringbuffer.append("〈/tr〉\n");

    int i1 = 0;

    j = 0;

    if(getDay(gCalendar) 〉 0)

    {

    stringbuffer.append("〈tr〉");

    for(; i1 〈 getDay(gCalendar); i1++)

    {

    stringbuffer.append("〈td align=right〉");

    if(sFont != null)

    stringbuffer.append(sFont + " 〈/font〉");

    else

    stringbuffer.append(" ");

    stringbuffer.append("〈/td〉\n");

    j++;

    }

     

    }

    for(; gCalendar.get(2) == i; gCalendar.add(5, 1))

    {

    int j1 = gCalendar.get(5);

    int k1 = (i1 + j1) % 7;

    if(k1 == 1)

    {

    stringbuffer.append("〈tr〉" + NEWLINE);

    j = 0;

    }

    stringbuffer.append("〈td align=right〉");

    j++;

    if(sFont != null)

    stringbuffer.append(sFont);

    String s;

    if((s = (String)config.get(String.valueOf(j1))) != null)

    {

    stringbuffer.append("〈a href=\"");

    if(s.toUpperCase().startsWith("HTT") || s.indexOf(".") 〉 0)

    {

    stringbuffer.append(s);

    if(s.indexOf("?") 〈 0)

    stringbuffer.append("?date=" + stringDate(gCalendar));

    else

    stringbuffer.append("&date=" + stringDate(gCalendar));

    }

    else

    {

    stringbuffer.append("javascript:" + s + "('" + stringDate(gCalendar) + "');");

    }

    stringbuffer.append("\"");

    if((s = (String)config.get(j1 + "target")) != null)

    stringbuffer.append(" target=\"" + s + "\"");

    stringbuffer.append("〉");

    stringbuffer.append(gCalendar.get(5));

    stringbuffer.append("〈/a〉\n");

    }

    else

    {

    stringbuffer.append(String.valueOf(j1));

    }

    if(sFont != null)

    stringbuffer.append("〈/font〉");

    stringbuffer.append("〈/td〉\n");

    if(k1 == 0)

    stringbuffer.append("〈/tr〉\n");

    }

     

    if(j 〈 7)

    {

    for(; j 〈 7; j++)

    {

    stringbuffer.append("〈td align=right〉");

    if(sFont != null)

    stringbuffer.append(sFont);

    stringbuffer.append(" ");

    if(sFont != null)

    stringbuffer.append("〈/font〉");

    stringbuffer.append("〈/td〉\n");

    }

     

    stringbuffer.append("〈/tr〉\n");

    }

    stringbuffer.append("〈/table〉\n");

    return stringbuffer.toString();

    }

     

    public Locale getLocale() //获取地区名

    {

    return loc;

    }

    public int getYear() //取得年份

    {

    return htmlCalendarYear;

    }

    public int getMonth() //取得月分

    {

    return htmlCalendarMonth;

    }

     

    public int getStyle() //取得日历的样式

    {

    return htmlCalendarStyle;

    }

    //设置动作的URI,target_frame 的值可以为_blank、 _parent、 _top、 _self。

    public void setAction(int day, String actionUri, String target_frame)

    {

    if(actionUri != null)

    {

    config.put(String.valueOf(day), actionUri);

    if(target_frame != null && target_frame.length() 〉 0)

    config.put(day + "target", target_frame);

    }

    }

    //设置一个月的所有天的超链接

    public void setActions(String actionUri, String target_frame)

    {

    for(int day = 1; day 〈= 31; day++)

    setAction(day, actionUri, target_frame);

     

    }

    //设置地区

    public void setLocale(Locale locale)

    {

    loc = locale;

    }

    //设置年份

    public void setYear(int htmlCalendarYear)

    {

    if(htmlCalendarYear 〉 0)

    {

    year = htmlCalendarYear;

    config.clear();

    }

    }

    //设置月份

    public void setMonth(int htmlCalendarMonth)

    {

    if(htmlCalendarMonth 〉= 1 && htmlCalendarMonth 〈= 12)

    {

    month = htmlCalendarMonth;

    config.clear();

    }

    }

    //设置日历的样式

    public void setStyle(int htmlCalendarStyle)

    {

    style = htmlCalendarStyle;

    }

    private String stringDate(Calendar calendar)

    {

    String strDay = String.valueOf(calendar.get(1));

    return strDay + twoDigits(calendar.get(2) + 1) + twoDigits(calendar.get(5));

    }

    private String twoDigits(int day) //为了日历中数字能够对齐,所以1-9 前将加0

    {

    String stringDay = String.valueOf(day); //取得day的值

    if(stringDay.length() == 1) //如果字符串长度为1

    return "0" + stringDay; //则在字符串前加零

    else

    return stringDay;

    }

    }

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Related Article
    What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

    MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

    Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

    ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

    What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

    MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

    MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

    Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

    MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

    Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

    MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

    MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

    MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

    ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

    MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

    ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Show More

    Hot Article

    How to fix KB5055612 fails to install in Windows 10?
    4 weeks agoByDDD
    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Roblox: Grow A Garden - Complete Mutation Guide
    3 weeks agoByDDD
    Nordhold: Fusion System, Explained
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Show More

    Hot Tools

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

    Show More

    Hot Topics

    Java Tutorial
    1674
    14
    CakePHP Tutorial
    1429
    52
    Laravel Tutorial
    1333
    25
    PHP Tutorial
    1278
    29
    C# Tutorial
    1257
    24
    Show More

    Public welfare online PHP training,Help PHP learners grow quickly!

    About usDisclaimerSitemap

    © php.cn All rights reserved