Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the JavaBean application steps in JSP

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about the steps of JavaBean application in JSP, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

First, write JSP files that use JavaBean, such as the demo JSP instance time.jsp in UFO:

Today is the first day of this year. This is the first week of this year. This is the first week of this month.

The second line of this statement in the above code means to introduce the ufobean package and the files in the package; secondly, pay attention to the statement, in which the value of id is custom, the class value is the package name plus dot plus JavaBean name, scope has several values, the default value is page, and session,application, etc., here use page. Time.jsp is used many times to get the property value of JavaBean (ShowCalendar) and display it on the page.

The JavaBean (ShowCalendar.java) code is as follows:

Packageufobean; importjava.util.*; publicclassShowCalendar {Calendarcalendar=null; intyear,dayOfMonth,dayOfYear,weekOfYear, weekOfMonth,dayOfWeek,hour,minute,second; Stringday,date,time; publicShowCalendar () {calendar=Calendar.getInstance (); Datetime=newDate (); calendar.setTime (time);} publicintgetYear () {returncalendar.get (Calendar.YEAR);} publicStringgetMonth () {intm=1+calendar.get (Calendar.MONTH) Stringmonths [] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; if (m > 12) return "0"; publicStringgetDay [m-1];} publicStringgetDay () {intn=getDayOfWeek (); Stringdays [] = {"day", "one", "two", "three", "four", "five", "six"} If (n > 7) return "week?" ; returndays [n];} publicStringgetDate () {returngetYear () + "/" + getMonth () + "/" + getDayOfMonth ();} publicStringgetTime () {returngetHour () + ":" + getMinute () + ":" + getSecond ();} publicintgetDayOfMonth () {returncalendar.get (Calendar.DAY_OF_MONTH);} publicintgetDayOfYear () {returncalendar.get (Calendar.DAY_OF_YEAR);} publicintgetWeekOfYear () {returncalendar.get (Calendar.WEEK_OF_YEAR) } publicintgetWeekOfMonth () {returncalendar.get (Calendar.WEEK_OF_MONTH);} publicintgetDayOfWeek () {returncalendar.get (Calendar.DAY_OF_WEEK)-1;} publicintgetHour () {returncalendar.get (Calendar.HOUR_OF_DAY);} publicintgetMinute () {returncalendar.get (Calendar.MINUTE);} publicintgetSecond () {returncalendar.get (Calendar.SECOND);}}

II. Compiling ShowCalendar.java files

Here is how to compile JavaBean under DOS: start-- run-- enter cmd-- through cd.. Or cd goes to the directory where JavaBean (ShowCalendar.java) is located, and after typing the command: javacShowCalendar.java, you can get the ShowCalendar.class byte file generated in the ufobean package. If you have modified the JavaBean, delete the old .class file and then recompile the JavaBean.

Third, access the time.jsp file in UFO and call JavaBean

1. Run time.jsp under the original directory of UFO

A) place time.jsp in the UFO\ webapps\ ROOT directory, place the ShowCalendar.class in the UFO\ webapps\ ROOT\ WEB-INF\ classes\ ufobean directory, start UFO, and enter the following address http://localhost:80/time.jsp, to run successfully.

B) place the time.jsp in the UFO\ webapps\ examples directory, place the ShowCalendar.class in the UFO\ webapps\ examples\ WEB-INF\ classes\ ufobean directory, start UFO, and enter the following address http://localhost:80/examples/time.jsp, to OK.

2. Create a new directory under the webapps directory

Establish a directory when you should pay attention to: the folder name is WEB-INF, not WEN_INF, pay attention to the middle bar to write right; folder name is classes rather than class;classes under the package name should also note that it is the same as your JavaBean package name, for example, you have the following statement in the JavaBean file: importufobean; means that you have introduced the name of the package ufobean, then the package name (folder name) under the classes folder should be ufobean. The remaining steps are compared with the methods in 1, b) and OK is done.

After reading the above, do you have any further understanding of the JavaBean application steps in JSP? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report