L3 network architecture instance basis

Source: Internet
Author: User
Basic Application: getting started with Java Web layer-3 architecture configuration

  1. Software Download:
  
1. Java
  
Jdk1.4.2 is used here.
: Http://dlc.sun.com/jdk/j2sdk-4154_2_07-windows-i586-p.exe;
  
2. Tomcat
  
Here, the tomcat version is 5.0, and the installation version or decompression version is acceptable.
: Http://apache.linuxforum.net/dis... a-tomcat-5.0.28.exe
  
3. Database
  
MySQL is recommended, but cannot be found for the time being. Due to the course design in our class, sqlserver will be used in the following practice (find an installation disk)
Note: connecting to sqlserver requires three jar files (starting with the file name ms), which can be downloaded here:
Http://www.softhouse.com.cn/html... 11250300001646.html
The complete configuration method is shown above.
  
  Ii. software installation:
  
1. Double-click to install JDK. After installation, add the following environment variables to my computer> Properties> advanced> environment variables> system variables:
  
(Assume that your JDK is installed in C:/JDK)
Jdk_home = C:/JDK
Classpath =.; % jdk_home %/lib/dt. jar; % jdk_home %/lib/tools. Jar
Add % jdk_home %/bin in path (already exists)
In this way, the JDK environment is successfully configured.
  
2. Double-click to install your tomcat. (It is recommended to install it in D:/tomcat)
  
Note: tomcat5.0.x can be used without configuring environment variables. However, if you need to compile the servlet, you must also put the two jar files of Tomcat into the environment variables. The specific method is as follows:
Choose my computer> Properties> advanced> environment variables> system variables to add:
Tomcat_home = D:/tomcat
Change classpath :.; % jdk_home %/lib/DT. jar; % jdk_home %/lib/tools. jar; % tomcat_home %/common/lib/servlet-api.jar; % tomcat_home %/common/lib/jsp-api.jar;
So tomcat has been fully installed.
Suggestion: Add % jdk_home %/bin in path; % atat_home %/bin
In this way, Tomcat tools can be used in Virtual DOS.
Finally, put the three jar files downloaded in step 1 to the common/lib directory in the Tomcat directory.
  
3. test:
  
Open the Tomcat (kitten pattern) Monitor Tool in the Start Menu, click Start server, and the green triangle is displayed to start. Open the browser and enter: http: // localhost: 8080/you can see that the kitten pattern indicates that the configuration is successful.
  
4. Install the database (sqlserver)
  
In Windows XP, you must install the Personal Edition or development edition (recommended for Personal Edition ).
  
Next is all the time (Microsoft's things are convenient). Here we notice that the local account is selected for the domain account, and hybrid verification is selected for the authentication (this is important, if you choose to connect to the database after system authentication in the Program), enter a password for your sa user (if you do not need to consider security, select "Empty Password)
  
  Iii. Formal programming:
  
1. Create a database
  
Open the Start menu and find the Enterprise Manager in the sqlserver shortcut group. Open the tree on the left and generally have a localhost connection. If a green triangle symbol exists, the database connection is successful. Click Create Database by email, create a new data table (for example, test) in the database you created, and create several fields in the data table.
  
Supplement: another way to create a table is to use SQL scripts to create a table. First, create the following file:
  
Test. SQL
Create Database Test
  
Use test
Create Table Test
(
Id int not null identity (1, 1 ),
Mark varchar (255 ),
Name varchar (255 ),
Sex varchar (255)
)
  
Then open the query analyzer in the sqlserver shortcut group in the Start Menu, click "file"-> "open", select test. SQL, and click "run.
  
2. Create a tomcat virtual directory
  
Create a folder (E:/wool for example) wherever you like, create a WEB-INF folder in the folder (note that it must be capitalized), and create a classes and Lib folder in the WEB-INF folder, put the Three jar files downloaded in step 1 (used to connect to the database) into the Lib folder. (Someone may ask: why is there no web. xml file? Don't worry, I will talk about it later)
  
3. configuration file and Connection Pool
  
This course design is difficult for many students. I have the simplest method here (I suggest configuring it in http: // localhost: 8080/admin, I personally think it is so troublesome and prone to errors). The following describes the steps:
  
First, create two files as follows:
  
Wool. xml
<? XML version = '1. 0' encoding = 'utf-8'?>
<Context docbase = "E:/Wool" Path = "/Wool" reloadable = "true" workdir = "E:/Wool/WEB-INF/classes">
<Resource Name = "JDBC/sqlserver" type = "javax. SQL. datasource"/>
<Resourcelink name = "JDBC/sqlserver" Global = "JDBC/sqlserver" type = "javax. SQL. datasource"/>
<Resourceparams name = "JDBC/sqlserver">
<Parameter>
<Name> driverclassname </Name>
<Value> com. Microsoft. JDBC. sqlserver. sqlserverdriver </value>
</Parameter>
  
<Parameter>
<Name> URL </Name>
<Value> JDBC: Microsoft: sqlserver: // localhost; databasename = test </value> <! -- Here test is the name of the database created at the first point in the third point -->
</Parameter>
  
<Parameter>
<Name> username </Name>
<Value> SA </value>
</Parameter>
  
<Parameter>
<Name> password </Name>
<Value> </value> <! -- If SQL Server is installed with a blank password, nothing is required here (note that no space is required) -->
</Parameter>
  
<Parameter>
<Name> maxactive </Name>
<Value> 4 </value>
</Parameter>
  
<Parameter>
<Name> maxwait </Name>
<Value> 5000 </value>
</Parameter>
<Parameter>
<Name> maxidle </Name>
<Value> 2 </value>
</Parameter>
  
</Resourceparams>
  
</Context>
  
Note: A problem found during the configuration process is that the above configuration file must delete the annotations to run successfully. For the moment, I don't know why. Theoretically, such annotations in XML files are acceptable and depressing.
  
Web. xml
<? XML version = "1.0" encoding = "ISO-8859-1"?>
<Web-app>
<Resource-ref>
<Description> connectdb </description>
<Res-ref-Name> JDBC/sqlserver </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
</Web-app>
  
After two files are created, put wool. XML in the/CONF/Catalina/localhost directory under Tomcat; put the Web. xml file in the E:/Wool/WEB-INF directory.
  
4. Test the connection of the Write Program
  
Test. jsp
  
<! -- Test the data source -->
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "javax. Naming. Context" %>
<% @ Page import = "javax. SQL. datasource" %>
<% @ Page import = "javax. Naming. initialcontext" %>
<% @ Page import = "Java. SQL. *" %>
<%
Datasource DS = NULL;
Try {
Context initctx = new initialcontext ();
DS = (datasource) initctx. Lookup ("Java: COMP/ENV/jdbc/sqlserver ");
  
If (Ds! = NULL)
{
Out. println ("datasource obtained! ");
Out. println ("<br/> ");
Connection conn = Ds. getconnection ();
Statement stmt = conn. createstatement ();
Resultset rst1_stmt.exe cutequery ("select * from test"); // The test here is the table name.
Out. println ("the following data is read from the Database ");
%>
  
<Table width = "100%" border = "2" cellspacing = "0" cellpadding = "0">
<Tr bordercolor = "# ff0000" bgcolor = "# cccccc" class = "style1">
<TH> name </Th>
<TH> gender </Th>
<TH> score </Th>
</Tr>
<%
While (RST. Next ())
{%>
<Tr bgcolor = "orange">
<TD> <% = RST. getstring (1) %> </TD>
<TD> <% = RST. getstring (2) %> </TD>
<TD> <% = RST. getstring (3) %> </TD>
</Tr>
<%
}
%>
</Table>
<%
Conn. Close (); // This is very important. The example provided by the instructors does not contain this sentence. Otherwise, the connection pool will be exhausted.
}
Else
Out. println ("connection failed! ");
  
}
Catch (exception ne)
{
Out. println (NE );
}
%>
  
Put the test. jsp file to E:/wool.
  
5. Start sqlserver and tomcat, and enter the following in the browser:
Http: // localhost: 8080/Wool/test. jsp
  
  4. Write at the end
  
The above method is used to help students configure engineering training (web layer-3 architecture) recently. It is the best method I have thought after referring to the experience of prawns on the network. Through the above steps, you can get started quickly for students who have not done Java or other web-based programming.

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.