JavaEE-01 JSP Dynamic Web base

Source: Internet
Author: User
Tags html comment tomcat server

Learning Essentials
    • Basic concept of B/s architecture
    • Creation and operation of Web projects
    • JSP page elements
    • MyEclipse creating and running Web projects
    • Web program debugging

A brief history of Web Web front-end technology Evolution three stages
    • WEB 1.0: Information broadcast.
    • WEB 2.0: Information interaction. Weibo, blogs, and more.
    • WEB 5.0: Mobile Internet.

Dynamic Web server-side technology evolution

Mainstream Web application Platform

Performance comparison

LAMP

Java EE

asp

Operating speed

More quickly

Fast

So so

Development speed

Very fast

Slow

So so

Operating loss

So so

Smaller

Larger

Degree of difficulty

Simple

Difficult

Simple

Operating Platform

Linux/unix/windows

Most platforms

Windows only Platform

Software architecture c/s architecture

Advantages: Fast response, personalized customization, strong transaction capacity, reduce server pressure, high security.

Disadvantage: C-terminal maintenance workload is not conducive to enterprise rapid deployment of applications.

b/S architecture

Advantages: Wide distribution, as long as the Internet browser can be. Flexible deployment, easy maintenance. Cross-platform.

c/S and BS hybrid architecture

Enterprise internal Operation data adopt C/S Architecture: External users do not directly access the database server, to ensure the relative security of the enterprise database. Intra-enterprise user interaction is strong, the data operation response speed faster.

Enterprise external Adoption of B/s architecture: Enterprise external users to modify and maintain data, the speed is slow, more cumbersome, the data dynamic interactivity is not strong. Suitable for simple data query and confirmation.

b/S Architecture definition

Common Web servers fall into three categories: Servers without applications (HTML files, etc.), servers with applications (such as JSP files), servers with applications and databases (such as the jsp+ database).

Working principle

b/S structure uses the request/Response mode to interact.

Httphttp Protocol Overview

HTTP Specifications 1.0 and 1.1 define the HTTP message format. HTTP messages consist of requests from the client to the server and the corresponding components from the server to the client, so the HTTP message is divided into two types: Request message and Response message.

Request Line

Status line
    • The status line format is as follows:

Http-version Status-code reason-phrase CRLF

Where http-version represents the version of the server HTTP protocol, Status-code represents the response status code sent back by the server, and Reason-phrase represents a textual description of the status code. The status code consists of three digits, the first number defines the category of the response, and there are five possible values.

    • Common Status Codes:
    1. OK: Client request succeeded.
    2. Bad Request: Client requests have syntax errors and cannot be understood by the server.
    3. 401 Unauthorized: Request is not authorized, this status code must be used with the Www-authenticate header domain.
    4. 403 Forbidden: The server receives the request but refuses to provide the service.
    5. 404 Not Found: The request resource does not exist, for example: The wrong URL was entered.
    6. Internal Server error: Unexpected errors occurred on the server.
    7. 503 Server Unavailable: The server is currently unable to process client requests and may return to normal after a period of time, for example: http/1.1 OK (CRLF).
View request and response information in the browser

Url

Uniform resource Locator, Uniform Resource Locator

Format:

Http://<IP address >:[port number]/path/[?< query information;]

For example:

Http://www.etc.com/book/index.html

http: Hypertext Transfer Protocol. Ftp,telnet

WWW: Represents a Web server

Etc.com: Server domain name

Book: directory on the site

An HTML file in the Index.html:book folder, which is a Web page.

Deployment of a Web application Tomcat server installation

    • Unzip version Tomcat considerations

Add a system variable named Catalina_home and set the installation directory with the value tomcat.

    • Start and stop the Tomcat server

Enter the http://localhost: port number in the IE Address bar.

Tomcat Server Directory

Directory

Description

/bin

Storage of script files for starting and stopping Tomcat under various platforms

/conf

Various configuration files for the Tomcat server

/lib

Various jar files required to store the Tomcat server

/logs

Log files that hold Tomcat

/temp

The Tomcat runtime is used to hold temporary files

/webapps

When you publish a Web app, the Web app's files are stored in this directory by default

/work

Tomcat places the servlet generated by the JSP in this directory

Tomcat Port Configuration

Modify the Tomcat port number by configuring the Server.xml file in conf in the Tomcat directory

<connector port= "8080" protocol= "http/1.1"        connectiontimeout= "20000"        redirectport= "8443"/>

  

On-Machine practice

Install Tomcat, start and stop Tomcat, and modify the Tomcat port number. and tested.

Web application

To create and deploy a Web project manually

1. Create a Web project in the development environment

Configure the default Access starting page in Web-inf/web.xml.

2. Publish as war file, copy to Tomcat 7.0\webapps directory and start Tomcat. Observe the WebApps directory and you can see the war automatically generated by the Web application. Access the project in IE.

3. The directory structure of the server-side Web project:

Directory

Description

/

Web App root directory, where all files are accessible to clients (JSP, HTML, etc.)

/web-inf

Store the various resources used by your app, which are not accessible to clients

/web-inf/classes

Store all the class files for the Web project

/web-inf/lib

Store jar files used by web Apps

On-Machine practice

1, manually create a Web project, the implementation of project publishing, and can be accessed through the browser input URLs.

2. Create a project in MyEclipse export as war file, deploy to server and access.

Integration of the development environment MyEclipse and Tomcat MyEclipse and Tomcat

Entry: windwos->prefereces->myeclipse->servers->tomcat7.x

Enable the TOMCAT7 server, associate the JDK.

Close the built-in Tomcat server.

Note: The settings are valid only for the working space

Creating projects and Deployment projects

Starting the Tomcat server in MyEclipse

On-Machine practice

Create the project in MyEclipse, deploy the project in MyEclipse, start the server in MyEclipse, and access the project in Internet Explorer.

JSP Concepts

Jsp:java Server Pages. Embed Java script code in HTML.

For example:

Enter http://localhost:8080/chapter01/index.jsp in the IE Address bar

Operating principle

JSP page element page directive
    • Role

Define properties for the entire page by setting multiple properties inside.

    • Syntax format (multiple values in a property are separated by the "," number)
<%@ Page Property 1 = "Property Value" Property 2 = "Property value 1, property value 2" ... Property N= "Property value N"%>

  

    • Common Properties
Property Describe Default value
Language Specifying the scripting language used by JSP pages Java
Import Use this property to refer to the class file used in the scripting language No
ContentType Used to specify the encoding used by the JSP page

Text/html,iso-8859-1

Small scripts and expressions

Expression: Displays the data, which the system calculates and displays as a value. (not to; end)

On-Machine practice

Requirements Description: Write a JSP page to calculate the sum of all primes between 1-100

Hint: 1, prime--in a natural number greater than 1, except 1 and this integer itself, can not be divisible by other natural numbers. 2, use out the built-in object output information.

Statement

When writing JSP page programs, there are times when you need to define member variables and methods for Java scripts, which you need to implement using JSP declarations.

Declaration Syntax Format:

<%! Declaration; [Declaration;] ...%>

  

Example: What if the following code needs to be used more than once in a page?

<%simpledateformat formater = new SimpleDateFormat ("yyyy year mm DD day"); String strcurrenttime = Formater.format (New Date ());%>

  

Usage claims

Comments in the JSP

Note: The HTML comment is persisted after the JSP file is compiled, and the JSP comment is discarded. Note of important information do not use HTML annotations.

Summarize

On-Machine practice

Requirements Description:

Write a JSP page that calculates several leap years in 2000-3,000.

Implementation ideas:

1. Declaring a method Boolean leapyear (int year), used to determine whether a leap year

2. Declare a variable count, used to count the number of leap years

3. Set the cycle condition from 2000-3,000

4. Call Boolean leapyear (int year) within the loop, changing the value of the variable count based on the return result

Tip Information:

Leap year judgment conditions: can be divisible by 4 and not divisible by 100, or can be divisible by 400.

JSP execution process Web container processing JSP file request requires 3 stages
    1. Translation phase
    2. Compile phase
    3. Implementation phase

After the first request, the Web container can reuse the compiled bytecode file

If a JSP file is modified, the Web container will re-translate and compile the JSP file.

Web program debugging and troubleshooting errors that are often made by running web programs
    • Tomcat not started
    • Web Apps not deployed
    • URL input Error
    • Directory cannot be referenced
    • JSP script error
Error debugging
    • Tomcat not started

If the server does not start, you need to modify the port number.

    • Web Apps not deployed

Confirm that the project has been deployed to the Tomcat server.

    • URL input Error

404 error, access to inaccessible URL resource.

    • Directory cannot be referenced

For example, create a file into Web-inf, resulting in a 404 error.

    • JSP script error

500 error.

Debug by Java program error: Read code logic, output data, Debug.

On-Machine Practice Requirements Description:
    • A static page of a news release system is converted to a JSP page and deployed to a Web project, and the JSP pages can be accessed through a browser.
    • Create a news release system database.
    • Set the character set encoding format to "UTF-8" by MyEclipse uniform
    • Adding page directives to HTML pages
    • Change the HTML suffix name to. jsp
Tips:
    • Set the character set encoding format to "UTF-8" by MyEclipse uniform
    • Adding page directives to HTML pages
    • Change the HTML suffix name to. jsp
Database Model Diagram

News Theme Table: Topics

Field

Data type

is empty

Note

Tid

Int

Whether

News topic number, primary key, self-increment

Tname

CHAR (50)

Whether

News theme, non-null, UNIQUE constraint

News Sheet: News

Field

Data type

is empty

Note

Nid

Int

Whether

News number, primary key, self-increment

Ntid

Int

Whether

News topic number, foreign key

Ntitle

CHAR (100)

Whether

News Headlines

Nauthor

CHAR (50)

Whether

Author

Ncreatedate

Datetime

Is

Release date, default current time

Npicpath

CHAR (200)

Is

Picture path

Ncontent

Text

Whether

News content

Nmodifydate

Datetime

Is

Edit Date

Nsummary

char (255)

Whether

News Summary

News comment form: Comments

Field

Data type

is empty

Note

Cid

Int

Whether

Comment number, primary key, self-increment

Cnid

Int

Whether

News number, foreign key

Ccontent

Text

Whether

Comment Content

CDate

Datetime

Whether

Comment Date, default current time

Cip

CHAR (100)

Is

Comment Person IP address

Cauthor

CHAR (100)

Is

Review authors

System User table: Users

Field

Data type

is empty

Note

Uid

Int

Whether

User number, primary key, self-increment

Uname

CHAR (20)

Whether

User name, non-null, UNIQUE constraint

Upwd

CHAR (20)

Whether

User password, non-empty

JavaEE-01 JSP Dynamic Web base

Related Article

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.