Type http: // localhost: 8080 / mypage.jsp in the address bar of your browser.
This way, the interface of the site can be unified, and the designer can concentrate on handling the user on the functional module.
Record, connect to the database, send email, etc. Each JSP file has the following structure:
<% @ Include file = "TOP.HTM"% "
<%
/ / Implement some functions
%
<% @ Include file = "bot.htm"% "
Maintaining the interface of the website is relatively easy, as long as Top.htm and Bot.htm can be modified, you can affect all
Web page.
V. Server parameter settings
JSWDK's web server parameters are saved in JSWDK-1.0.1Webserver.xml, playing with Windows Word board
Open and edit this file to modify the default settings. This section is mainly for JSWDK, Linux under TO
The setting method of MCAT is slightly different.
JSwdk Default Document Directory is jswdk-1.0.1WebPages, which can create subdirectory in this directory, such as JSWDK-1.0.1Webpagestest, you can use http: // localhost / test / test / TEST
Ask this directory, in order to make this sub-directory to execute the JSP program, you must also be in WebServer.xml
"And, you must also establish a JSWDK-1.0.1WebPageStestWeb-Inf directory and from JSWDK-1.0.1
Copy the following four files in the webpagesWeb-INF directory: mappings.properties, mime.p
Roperties, servlets.properties and webapp.properties. Complete these processes can
Notify the JSWDK's web server to perform the JSP program in http: // localhost / test.
Javabean
One of the JSP web attractive places is to combine the functionality of the program in the web page.
JavaBean is a Java class (Class), which has some function or method or by encapsulation attributes or
Handle an object of a business. JavaBean is organized into package for management,
In the event, put a set of Javabeans in a certain directory, plus a Package a certain directory.
This example is TEST. Directory TEST must be placed in the system environment classpath included, the system can
Find the Javabean in it. JSWDK will jswk-1.0.1webpagesWeb-Infjspbe in the default state
ANS joins ClassPath. When you build your own Javabean and Package, you will not be in this directory.
Lost a simple way.
Here is a simple JavaBean framework. Create a text file HelloWorld with a text editor
.java, and saved in the JSWDK-1.0.1WebpagesWeb-Infjspbeanstest directory, its contents are as follows
:
Package test;
Public class helloworld {
Public string name = "my first bean";
Public String gethi ()
{
Return "Hello from" Name;
}
}
After HelloWorld.java, after the DOS state, enter the directory JSWDK-1.0.1WebpagesWeb-i
NfjspBeans, compiled HelloWorld.java with JDK's Javac commands as follows:
Javac HelloWorld.java
Note that Java is case sensitive, in the program, the case in the compile command line cannot be written
. Compiling success reveals a JavaBean. See how to use this Javabean in JSP.
Create a text file hi-bean.jsp with a text editor, and save it in the JSWDK-1.0.1WebpageStest directory, its contents are as follows:
HEAD
/ "
<% = Hellobean.gethi ()% "
<%
Hellobean.name = "jsp";
Out.print (Hellobean.Gethi ());
%
Body "
Html
In the JSP page, use the
For Hellobean. Readers can see the settings from this simple example, get JavaBean properties, and tune
Use the JavaBean method. Type http: // localhost: 8080 / in the address bar of the browser
Test / hi-bean.jsp, the result is shown in Figure 3. Note that if you modify and recompile Javabe
The result of the AN program that needs to be turned off and restarted the JSWDK's web server. Such as
If you only modify the JSP file, you don't have to restart the JSWDK's web server.
Although this only completed a very simple JavaBean framework, but follow this framework to design
A variety of diverse JavaBeans. For example, access data from JSP is usually achieved by JavaBean.
.
7. Database connection
Database connection is the most important part of the dynamic website, the technology connected to the database in Java is JDBC
(Java Database Connectivity). Many database systems with JDBC drivers, Java
The order is connected to the database through the JDBC driver, performing queries, extracting data, etc. Sun also
Developed JDBC-ODBC Bridge, using this technology Java program to access the number with an ODBC driver
According to the library, most database systems have an ODBC driver, so Java programs can access such things such as OR.
ACLE, SYBASE, MS SQL Server, and MS Access and other databases. Here is how to use Access
Now a dynamic FAQ (FAQ) website. First create an Access database FAQ.mdb,
The table FAQS has a field ID (automatic incremental, and is a primary keyword), SUBJECT (text, long
Degree 200), Answers. Some common problems and answers for programming knowledge can be stored in this table.
case,
Then, add System DSN in the ODBC Datasource module of Control Panel.
, Name FAQ, and point to FAQ.mdb. Create a JavaBean, named FAQ.JAVA, and save it in JSW
DK-1.0.1WebpagesWeb-InfjspBeanstest directory. The content of FAQ.java is as follows: package test;
ResultSet RS = Workm.executeQuery ("SELECT * FROM FAQS"); String Tt;
While (rs.next ()) {
Tt = rs.getstring ("Answer");
Out.print ("
OUT.PRINT ("
}
Rs.close ();
%
Type http: // localhost: 8080 / test / faq.jsp, FAQ.js in the address bar of the browser
P call JavaBean, read the content from the database and output it.
Limited to the space, this article does not list complex examples of JSP-JavaBean-JDBC / ODBC-database, readers can
Found and downloaded to the database connection example from the last recommended URL in this article.
Eight, technical analysis
Microsoft's ASP technology is also a dynamic web development technology. JSP and ASP are very similar in form
The ASP programmer recognizes <% "and <% =%." But in-depth exploration, you will find them.
A lot of differences, the most important of which have the following three points:
1, JSP is more efficient and safe
ASP is stored in the source code to interpret how to operate, each ASP web page call needs to explain the source code.
, Running efficiency is not high. In addition, the vulnerability of IIS has made many website source programs, including the author
With ASP development, the ASP program is all downloaded.
JSP is compiled into a zona code before execution, byte code by Java Virtual Machine (Java)
Virtual Machine) Explain the execution, the efficiency of the source code is high; the server is also available on the server.
The HE mechanism can improve the access efficiency of the bytecode. The first call JSP page may be slightly slow because it is compiled
It is a lot of cache. At the same time, the JSP source program is unlikely to be downloaded, especially Javabean
The program can be fully placed in an abroad directory.
2, JSP components (Component) is more convenient
ASP expands complex features with COM, such as file upload, email, and processing business or complex
Calculate the separation to become an independent reusable module. JSP achieves the same functionality through JavaBean
Charge.
In development, COM development is far more complicated and cumbersome, and the learning asp is not difficult, but learns to develop CO.
M is not simple. Javabean is more simple, from this example, it can be seen that JavaBean is very
Convenience.
In terms of maintenance, COM must register on the server. If you modify the COM program, you must re-register.
Even must shut down and restart. JavaBean does not need to register, put it in the directory contained in ClassPath.
Ok. If Javabean has modified, JSWDK and Tomcat also need to turn off and re-run (but not shutdown), but developers have promised that they will do not need to turn off the server in future versions.
In addition, JavaBean is complete OOP, which can be easily established for different business processing functions.
Subject library, such as user rights control, email automatic reply, etc.
3, JSP adaptation platform is more
ASP is currently only available for NT and IIS. Although there is a CHILISoft plugin under UNIX to support ASP, ASP this
The function of the body is limited, and it must be expanded through the combination of ASP COM. It is very difficult for COM in Unix
.
JSP is different, almost all platforms support Java, JSP Javabean can pass unobstructed under all platforms
. IIS under NT passes a plugin, such as JRun (http://www3.allaire.com/products/
JRUN /) or servletexec (http://www.newatlanta.com/) can support JSP
. The famous Web server Apache has been able to support JSP. Because Apache is widely used in NT, UNIX and
On Linux, JSP has a wider range of running platforms. Although the NT operating system now accounts for a large market share
Amount, but the advantage of UNIX in terms of server is still very large, and the new rise Linux is not small.
Transplant from a platform to another platform, JSP and JavaBean don't even need to recompile because Java words
The section code is standard and the platform is independent. The author will get LIN in the JSP page of the experiment under NT.
UX is running, it feels very satisfied.
Nine, conclusions
In summary, JSP can be described as a tool to build a dynamic website, so it is recommended to readers, I wish you master J
SP has developed an excellent website. ASP programmers also tried, there is session, request, in JSP, Request,