Author: Lance Lavandowska compilation: blueski
If you often go to the Servlet or JSP newsgroup or email list, you will certainly see a lot of discussions about the Model I and Model II methods. Which one is used depends on your personal preferences, team work strategies, and whether you adopt Orthodox OOP.
Simply put, Model I integrates the business logic and presentation code (for example, in HTML ); model II advocates putting all code out of content representation to the maximum extent.
Model I: simple single-layer application
If you are in an environment where everyone is proficient in Java and HTML, or you are doing all the work alone, if everyone has a clear programming structure and ideas, this method will be very effective, however, such assumptions are not covered in this article. The first advantage of this method is that if your application changes, you only need to maintain a file. The biggest drawback is readability! Unless you are very careful, your HTML and Java code will be mixed, making it difficult to maintain.
In the following example, we will add a TimeZone element to convert it into a JSP file, which will return the expected TimeZone based on time. If no TimeZone is submitted, the default time is the default time of the server.
========================================================== ====================================
<Xml version = "1.0"?>
<H1> Time JSP </H1>
<Jsp: scriptlet>
// The parameter "zone" shall be equal to a number between 0 and 24 (random sive)
TimeZone timeZone = TimeZone. getDefault (); // returns the default TimeZone for the server
If (request. getParameterValues ("zone ")! = Null)
{
String timeZoneArg = request. getParameterValues ("zone") [0];
TimeZone = TimeZone. getTimeZone ("GMT +" + timeZoneArg + ": 00 ");
// Gets a TimeZone. For this example we & acute; re just going to assume
// Its a positive argument, not a negative one.
}
// Since we & acute; re basing our time from GMT, we & acute; ll set our Locale to Brittania, and get a Calendar.
Calendar myCalendar = Calendar. getInstance (timeZone, Locale. UK );
</Jsp: scriptlet>
<% = MyCalendar. get (Calendar. HOUR_OF_DAY) %>:
<% = MyCalendar. get (Calendar. MINUTE) %>:
<% = MyCalendar. get (Calendar. SECOND) %>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.