MVC design pattern

Source: Internet
Author: User

Chapter 2: MVC design mode
What is the MVC design pattern?
1) Two specifications were developed in the early stages of JSP, called Model1 and Model2.
2) In Model1 mode, jsp has two roles: presentation layer and control layer, which are suitable for simple application development.
3) different from Model1, Model2 pulls Servlet into the control layer, improving the maintainability and reusability of web pages.
4) Mvc is divided into three layers: model --- View ---> Control)
5) The model is the data service layer (JavaBean), the view is the Jsp (presentation layer), and the Controller (Servlet)
6) The view sends the request to the Controller, the Controller calls the model to process the volume, and then determines which view is used to display the data returned by the model.
7) the visible controller plays two roles. 1: Call JavaBean.2: call another view
8) log on to the page (login. jsp) View --- check (Servlet) controller ----> call loginBean --> return result ---> index. jsp (View)
Application Example of MVC
1) User Login
2) Paging example
3) Product Management

Solve garbled characters:
String Name = new String (request. getParameter ("txtName"). getBytes ("iso-8859-1 "));
Out. print (Name );
Modify the hosts page of a web application
Copy the following part of \ conf \ web. xml under TomCat to the Web Application
Under web. xml

<Welcome-file-list>
<Welcome-file> default.html </welcome-file>
<Welcome-file> default.htm </welcome-file>
<Welcome-file> default. jsp </welcome-file>
</Welcome-file-list>
Set parameters in web. xml and read the parameters on the jsp page.
Procedure
1: Add the following code to web. xml:
<Context-param>
<Param-name> uid </param-name>
<Param-value> chen </param-value>
</Context-param>
<Context-param>
<Param-name> pwd </param-name>
<Param-value> 123 </param-value>
</Context-param>
2:
// Jsp
Application. getInitParameter ("arameterName ");
// Servlet
Request. getSession (). getServletContext (). getInitParameter ("arameterName ");

++ ++ ++

If you do not want to bring up a dialog box to redirect the page:
Response. sendRedirect ("login.html ");
If you want to jump to the page after the dialog box is displayed:
Use javascript scripts
Out. println ("<script> alert ('prompt information'); window. location = 'destination page' </script> ");
Form Verification
1: Check the data filled in by the customer on the client.
If all the data is valid, you can submit it,
If one item of data is invalid, the submission is blocked.
2: How to verify the form:
Steps:
1) Compile a function as check
2) verify the data validity in the function
3) write in the submit event of the form:
Return check ();
Regular Expression
1: Regular Expressions are some wildcards.
2:
A: ^: Indicates start
B: End
C: []: represents any character in brackets:
For example:
[0-9]: Number
[0-9a-z]: Numbers and lowercase letters
[0-9a-zA-Z]: composed of numbers and English letters
[0-9a-zA-Z _-]
D :{}: indicates the number of characters that appear. It must be written after [].
For example:
[0-9] {3}: three numbers are required.
[0-9a-zA-Z] {4}: it must consist of four digits or letters
[0-9] {2,}: must contain at least two digits
[0-9a-zA-Z] {5, 8}: it must consist of 5 to 8 digits and English letters
E: \.: equivalent "."

Example:
1: The user name consists of 5 to 8 digits and English letters
^ [0-9a-zA-Z] {5, 8} $
2: Email compliant
^ [0-9a-zA-Z _-] {1,} @ [0-9a-zA-Z] {1,} \. [a-zA-Z] {1,} $

1: must contain @
2 cannot be in front
3 cannot be at the end
4: contains at least one.
5:. cannot carry the @ symbol on ai
6:. Cannot start


Use of Regular Expressions:
If (! Form. Form element. value. match ("Regular Expression "))
{
.......
Return false;
}

++ ++ +
How to configure a Web application for local debugging
1: Create a *. xml file with the same name as the Web module under the \ conf \ Catalina \ localhost folder of TomCat
Code:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Context path = "/Web template name .."
DocBase = "F: \ Java oop \ java_excecise \... project name... Web template name .."
Debug = "0" reloadable = "true"
Privileged = "true"/>
2: start Tomcat
Find the Tomcat folder, find bin \ startup. bat, and configure
Write down below the second horizontal line
Set JAVA_HOME = D: \ JBuilder2005 \ jdk1.4 [jdk path]

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.