js| Tutorial
//-------------------------------------------------------------------------------------------
Concept server for client and server side:
Broadly speaking, servers are divided into two types (hardware servers, software servers)
Hardware server: Refers to the relative PC, the performance and stability of the better, the use of special hardware computer.
Software server: Colloquially, refers to the installation of some kind of service software, and can provide the corresponding service machine, we call it the server.
There are many kinds of service software, which are common:
WWW service software: PWS, IIS, APACHE
Java EE Middleware Application server: WebSphere, Silverstream
JSP engine (Weak WWW service function): Tomcat,resin,weblogic,jrun
SMTP, Pop3:iis's Smtp,exchange,lotus Domino
Ftp:iis with
Client: Relative to the server, is to enjoy a certain kind of service side, is called the client. However, to enjoy a service you must also install the appropriate software, such as (Ie/netscape, Outlook/foxmail, CuteFTP)
Data type
The basic types have the following four kinds:
int length data types are: Byte (8bits), short (16bits), int (32bits), Long (64bits)
Float length data types are: Single precision (32bits float), double precision (64bits double
Boolean-type variables have the values: Ture, False
Char data types are: Unicode characters, 16-bit
Corresponding class type: Integer, Float, Boolean, Character, Double, short, Byte, Long
Conversion principles:
Converting from low precision to high precision
BYTE, short, int, long, float, double, char
Note: Two char operations, automatically converted to int, when char and other types of operations, will be automatically converted to int type, and then do other types of automatic conversion
Base type conversions to class type
Forward conversion:
To create a new class-type variable by using the class wrapper
Integer a= new Integer (2);
Reverse conversion:
Converting by class Wrapper
int B=a.intvalue ();
class type to string conversion
Forward conversion:
Because each class is a subclass of the object class, and all object classes have a ToString () function, you can convert it by using the ToString () function.
Reverse conversion:
To create a new class-type variable from the class wrapper
Eg1:int i=integer.valueof ("123"). Intvalue ()
Description: The above example converts a string into an integer object, and then calls the object's Intvalue () method to return its corresponding int value.
Eg2:float f=float.valueof ("123"). Floatvalue ()
Description: The above example converts a string into a float object, and then calls the object's Floatvalue () method to return its float value.
Eg3:boolean b=boolean.valueof ("123"). Booleanvalue ()
Description: The above example converts a string into a Boolean object, and then calls the object's Booleanvalue () method to return its corresponding Boolean value.
Eg4:double d=double.valueof ("123"). Doublevalue ()
Description: The above example converts a string into a double, and then calls the object's Doublevalue () method to return its double value.
Eg5:long l=long.valueof ("123"). Longvalue ()
Description: The above example converts a string to a long object, and then calls the object's Longvalue () method to return its long value.
Eg6:char=character.valueof ("123"). Charvalue ()
Description: The above example converts a string into a character object, and then calls the object's Charvalue () method to return its corresponding char value.
Conversion of base type to string
Forward conversion:
such as: int a=12; String b;b=a+ "";
Reverse conversion:
Through the class wrapper
Eg1:int I=integer.parseint ("123")
Note: This method can only be applied to strings converted to integer variables
Eg2:float f=float.valueof ("123"). Floatvalue ()
Description: The above example converts a string into a float object, and then calls the object's Floatvalue () method to return its float value.
Eg3:boolean b=boolean.valueof ("123"). Booleanvalue ()
Description: The above example converts a string into a Boolean object, and then calls the object's Booleanvalue () method to return its corresponding Boolean value.
Eg4:double d=double.valueof ("123"). Doublevalue ()
Description: The above example converts a string into a double, and then calls the object's Doublevalue () method to return its double value.
Eg5:long l=long.valueof ("123"). Longvalue ()
Description: The above example converts a string to a long object, and then calls the object's Longvalue () method to return its long value.
Eg6:char=character.valueof ("123"). Charvalue ()
Description: The above example converts a string into a character object, and then calls the object's Charvalue () method to return its corresponding char value.
JSP Basic Instruction------
1--Script Tag
Declaration will be used in the language: <%@ page language= "Java"%> indicates the JSP directive, indicating that the following scripting code will take the Java language syntax
Class in reference Package: <%@ page import= "java.util.*"%> represents the class to use in the Java.util package
Declaring variables: <%! int count=0;%> declares an integer variable and assigns an initial value of 0
To declare a method:
<%!
int show (int val) {
return Val;
}
%>
Output expression: <%=2*X%> The value of the direct output expression, X must be a previously declared variable (not a semicolon), equivalent to the <%=%> in ASP
JSP annotation character: <%--here are comments--%> is a JSP annotation, will be ignored on the server side, also do not translate into HTML annotation, can not see when the client view the source code.
Contains another JSP file:% jsp:include page= "another:jsp"%> represents the insertion of another file another.jsp content on the current page
Normal JSP statement:
<%
for (int i=0,i<10,i++)//jsp body part
Out.println (i+ "
");
%>
2. Directive---JSP instruction has page, include two kinds
Page directive (properties: 6)
Language properties:
<%@ page language= "Java"%>//indicate the language used
Import Property:
<%@ page import= "java.util.*"%>//Load Package
Note: In Java, to load multiple packages, use import to separate them and separate them with semicolons;
In a JSP, if you specify multiple packages with an import, separate them with commas.
such as: <%@ page import= "java.util.*,java.lang.*"%>
You can also <%@ page import= "java.util.*"%>
<%@ page import= "java.lang.*"%> (but does not advocate this use, nonstandard.
Session Properties:
<%@ page session= "true or false"%> the default session value is True
such as: <%@ page session= "true"%>
<%
if (Session.getvalue ("name") ==null)
Session.putvalue ("name", "123456");
Else
Session.putvalue ("Name", Session.getvalue ("name") + "1");%>
<% out.println (Session.getvalue ("name"));%> if session= "false", a compilation error occurs.
ErrorPage Properties:
Refers to the program specified by ErrorPage to handle the writing when the current page program has an error:
<%@ page errorpage= "errorpage.jsp"%>
such as: test.jsp: <%@ page errorpage= "errorpage.jsp"%>
<%!int i=0;%>
<%=7/i%>
ERRORPAGE.JSP:
<%@ page iserrorpage= "true"%>
<%=exception%>
When you run test.jsp, you will see an error message that is removed by 0.
Iserrorpage Properties:
Indicates whether the current program is an exception handler for another program. Regardless of whether it is set, the exception is directed to the current program, and the question is whether the current program can get an object for this exception. If set to true, an object that will produce an exception is exception and can be used in code, and if False, using the exception program will make a compile-time error. If you change the previous example to False, the following error occurs:
error:500
Unable to compile class for JSP
Writing: <%@ page iserrorpage= "true"%>
ContentType Properties:
Specifies the MIME type and the character encoding of the JSP file, all of which are routed to the client first. MIME types are: Text/plain, text/html (default type), Text/html, Image/gif, Image/jpeg, Image/jpeg
Default character encoding method: Iso8859-1
Include directives
Function: is used to insert the contents of a static file into the current page, which may be an HTML file, JSP file, or other text file, in the following format:
<%@ include file= "Include.inc"%>
Such as:
NATIVE.JSP:
native file start here.
<%@ include file= "Include.inc"%>
Native file end is here.
Include.inc:include file start here.
<%! String str= "Here is" include
//---------------------------------------------------------------
Script
The JSP script is the code block written in the script language specified by the page instruction language attribute, and the function that needs to be completed with JSP is mainly implemented here. The basic Java language is currently used.
The code block must be fully compliant with the Java syntax, but it can be used in conjunction with HTML text. In fact, whatever it is, it will be converted to a servlet, which is the same in the servlet.
such as: First output 5 blank lines, and then output "Hello"
Correct:% for (int i=0;i<5;i++)%>
<%;%>
Hello
Wrong: (one line of BR; one line hello) ===============
<% for (int i=0;i<5;i++)%>
Hello
Error is equivalent to:% for (int i=0;i<5;i++) {%>
Hello
<%}%>
Action (<%jsp%>)
JSP provides the action instructions include: include, Forward, Usebean, GetProperty, SetProperty
Include actions
The method by which the JSP adds another file to the current page.
Forward action
To redirect the current page to another page, the client sees an address that is the address of page A,
and the actual content is the content of page B.
Such as:
This is AA.
This is BB.
Note: No content can be exported to the client until the forward is used, otherwise an exception will occur.
Usebean Action
This action is used to generate a bean component and set its ID number and scope of use
action for Bean
Id= "Beanname": Defines the name of the generated bean component, cannot duplicate it, and the value of scope is the best, otherwise the JSP engine will identify the one that was first created.
Scope= "Page|request|session|application": Defines the scope of the bean's activity, and the bean can only be used in the scope it defines.
It cannot be accessed outside its range of activities.
The range the JSP sets for it is:
Default use scope of Page:bean
Request: A JSP file that acts on any of the same requests until the page has finished executing and sends back a response to the client or has previously been transferred to another file in some way, such as redirection, linking, and so on. You can also access the bean by using the request object, such as: Request.getattribute (Beanname)
Session: In the lifetime of the entire session, any changes to this bean property during the session's lifetime will affect the call to this bean in another page in this session and another request. However, session=true must be specified beforehand with the page directive in the file in which the bean was created.
Application: Within the life cycle of the entire application, any changes to this bean property within the application cycle will affect another page in this application, Another request and a call to this bean in another session.
Class= "Package.class": Example of a bean with the class attribute, where the package name must be specified by the keyword package in the class.
Type= "Package.class"
class= "Package.class" type= "Package.class"
Beanname= ' {package.class| <%=expression%>} ' type= ' Package.class '
such as: tt.jsp
<%=student.getname ()%>
<% student.setname ("wll"); %>
=====tt.jsp file to this ============
student.java//here begins the content of Student.java
Package mine;
public class student{
Long Classno;
String name;
int age;
Boolean sex;
Public student () {
classno=12345;
Name= "AAAA";
age=21;
Sex=true;
}
Public long Getclassno () {
return classno;
}
public void Setclassno (long no) {
This.classno=no;
}
Public String GetName () {
return name;
}
public void SetName (String name) {
This.name=name;
}
public int getage () {
return age;
}
public void Setage (int age) {
This.age=age;
}
public Boolean getsex () {
return sex;
}
public void Setsex (Boolean sex) {
This.sex=sex;
}
}
//----------------------------------------------------------------------------------------
Note:
When you scope= "page", the test.jsp file is run, and the initial value of name is AAAA. Although in the JSP file
Reset to "WLL", but still "aaaa" after refreshing
When scope= "Session", run the test.jsp file, the initial value of name is "AAAA". Although in the JSP text
The item is reset to "WLL", but is still "wll" after the refresh, as long as the window is not closed, any refresh or hit
Open a new window, all output "wll". Until all windows are closed, and then run test.jsp files, lose
Will be "AAAA" for the initial value.
When scope= "Application", run the test.jsp file, the initial value of name is "AAAA". Although in the JSP
The file is reset to "WLL", but is still "wll" after refreshing, as long as this window is not closed, any refreshes or
Opens a new window with the output "WLL". Even if you close all windows and run the test.jsp file, you lose
Out is still "wll". Unless the service is shut down and restarted, the test.jsp file is run, and the output of name is
Initial value "AAAA".
When scope= "Request", create a new file test1.jsp the same content as test.jsp. First in the browser
Row test.jsp file, the value of the output name is the initial value "AAAA". Then run the test1.jsp file in the browser, at which point the output is "WLL" because they are the same request.
GetProperty Action
Function: Used to return the property value of a bean component that has been created:
Name: corresponds to the value of the ID when the bean component was created with Usebean
Property: Indicates the value of which attribute to get
For example: Get the attribute value of the student component in the precedent:
Equivalence: <%=student.classno%>
The output results are:
12345 AAAA 21
SetProperty Action
Function: To set the property value of a bean component that has been created: name: Corresponds to the value of the ID when creating the Bean component with Usebean: Indicates the property name value to which you want to set the property value: For a set property value such as the student component in the preceding example, the property equivalence:% student.age=33;%> output is: 56789 bbbb 33