ASPJSP development environment Configuration whole process

Source: Internet
Author: User
Tags anonymous connect mysql mysql client variables stmt variable access
js| process

Mysql

Download version: Mysql-4.1.13-win32.zip (Windows downloads)

Http://dev.mysql.com/downloads/mysql/4.1.html

JDBC Driver

Download version: Mysql-connector-java-3.1.10.zip

Http://dev.mysql.com/downloads/connector/j/3.1.html

Download J2SDK

Download version: Jdk-1_5_0_04-windows-i586-p.exe

http://java.sun.com/j2se/1.5.0/download.jsp

Download Tomcat

Download version: Jakarta-tomcat-5.5.9.exe

http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi

Install, configure J2SDK:

Perform J2SDK setup, install by default, or customize the path, but modify the following configuration

Configure J2SDK:

To configure environment variables:

My Computer-> Properties-> the advanced-> environment variable-> system variable add the following environment variables:

Java_home=c:\program files\java\jdk1.5.0_04
Classpath=%java_home%\lib\dt.jar;
%java_home%\lib\tools.jar;
Path=%java_home%\bin;
%SystemRoot%\System32;
%SystemRoot%;
%systemroot%\system32\wbem


Write a simple Java program to test whether the J2SDK has been installed successfully:

public class Hello
{
public static void Main (String args[])
{
System.out.println ("Hello");
}
}


Save the program as a file with a file name of Hello.java.

Open a Command Prompt window and enter the directory where Hello.java is located, and type the following command:

Javac Hello.java
Java Hello


At this point if the print out Hello is installed successfully, if not printed out this sentence, carefully check the above configuration is correct.

Note The System Folder option should make sure that "Hide extensions for known file types" is not checked.

Install, configure Tomcat

Perform the Tomcat installer, install by default, or customize the path, but modify the following configuration:

My Computer-> Properties-> Advanced-> environment variable-> system variable add the following environment variables

Catalina_home=c:\program Files\apache
Software Foundation\tomcat 5.5
Catalina_base=c:\program Files\apache
Software Foundation\tomcat 5.5


Modify the Classpath in the environment variable, add the Servlet-api.jar under the Tomat installation directory Common\lib to Classpath, and modify the Classpath as follows:

Classpath=%java_home%\lib\dt.jar;
%java_home%\lib\tools.jar;
C:\Program Files\apache Software Foundation\tomcat 5.5\common\lib\servlet-api.jar;


Start Tomcat, access http://localhost:8080/in IE, and if you see the Tomcat Welcome page, the installation is successful.

installing MySQL

Decompress Mysql-4.1.13-win32.zip, run Setup.exe

The first appears is the Installation Wizard welcome interface, click "Next" to continue, select the installation type, select "Custom" Custom, then click "Next" Next, a Custom installation interface, select the installation path: C:\MySQL Server 4.1 (customizable) point "OK" Return to the custom installation interface, the path has changed to set the path, point "Next", ready to start the installation, click "Install" to start the installation, after the completion of the creation of the MySQL.com account interface.

If you are using MySQL for the first time, select "Create anew free mysql.com accout", click "Next", enter your email address and set your own password for login to mysql.com, and then click "Next" to enter the second step, Fill in the name and other related information, fill out the point "next", enter the third step, fill in the phone number, company name and other information, click "Next", and then appear preview you just fill in the information of the interface, click "Next" appears installation completion interface.

Note that there is a configuration Wizard option (Configure the MySQL Server now) and it is recommended that you configure your MySQL immediately. Many say the installation of MySQL can not start after the reason is not configured MySQL.

Click "Finish" to complete the installation and start to configure MySQL, click "Next", and enter the configuration type Selection page. Select "Detailed Configuration" (Detailed configuration), click "Next", and enter the service type Selection page. Choose "Developer Machine" (Developer Machine), so that the system does not occupy a lot of resources, click "Next", enter the Database Usage Selection page.

Select "Multifunctional Database", click "Next", go to the Select InnoDB data storage location page without changing the settings, put it directly in the installation path installation directory, and then click "Next", Select the number of concurrent joins for MySQL, select "Manual Setting", set to 100 (set as appropriate, as required)

Click "Next" to configure MySQL's port in the TCP/IP communication environment to select the default 3306 port. Click "Next" to choose the character settings in MySQL, and note that the choices here will affect whether you can use Chinese in MySQL. Select the gb2312 character set to support Simplified Chinese, point "Next", set Windows service options, and note that the choice here is critical.

"Install as Windows Service" must be checked, this is the MySQL as Windows services run. "Service Name" is used under the default "MySQL" under "Launch the MySQL Server automatically" must be checked, so that when Windows starts, MySQL will automatically start the service, or you will manually start MySQL.

Many people say that after installing MySQL, unable to start, cannot connect, there are 10061 errors, the reason is here. Point "Next", set the root account root login password, "Modify security Settings" is to set the root account password, enter the password you set.

"Create a Anonymous account" is the creation of an anonymous accounts, which will cause unauthorized users to access your database illegally, there are security concerns, the proposal does not check.

Point "Next", the MySQL Configuration wizard will be based on all the settings above you to configure MySQL, so that the operation of MySQL to meet your needs, point "Execute" Start configuration, when the "Service started successfully", the description of your configuration completed, MySQL Service started successfully

Point "Finish" completed, the entire MySQL configuration completed, the rest is to use MySQL client connection MySQL server, and then used.

To install the JDBC driver:

Decompression Mysql-connector-java-3.1.10.zip

is going to be using Mysql-connector-java-3.1.10-bin-g.jar

and Mysql-connector-java-3.1.10-bin.jar

Configuration

Mysqlforjdbc subdirectories are created in the C:\Program Files\java directory, and access to the directory will be mysql-connector-java-3.

1.10-bin.jar to this directory

Enter C:\Program

Files\java\jdk1.5.0_04\lib directory to copy Mysql-connector-java-3.1.10-bin-g.jar to this directory

Then configure Classpath to append%java_home%\lib\mysql-connector-java-3.1.10-bin-g.

Jar C:\Program

Files\java\mysqlforjdbc\mysql-connector-java-3.1.10-bin.jar to the environment variable.

After appending the environment variables are as follows:

Classpath=%java_home%\lib\dt.jar;
%java_home%\lib\tools.jar;
C:\Program Files\apache Software
Foundation\tomcat5.5\common\lib\servlet-api.jar;
%java_home%\lib\mysql-connector-java-3.1.10-bin-g.jar;
C:\Program FILES\JAVA\MYSQLFORJDBC
\mysql-connector-java-3.1.10-bin.jar;


The purpose of this configuration is to have the Java application find the driver to connect to MySQL.

View and start the MySQL service

After installing MySQL under Windows XP, it has started the service automatically and has a shortcut connection to its client in the Start menu, which can be viewed through Windows Service Manager. "Start"-"Run", enter "Services.msc", carriage return.

Windows Service Manager pops up, and then you can see the service item with the service name "MySQL", which is labeled "Started" on the Start menu-All Programs-mysql-mysql Server 4.1-mysql Command Line The client uses the shortcut connection of the clients to enter the password set at installation.

Use of the database

After MySQL is installed, in the Start menu-All Programs-mysql-mysql Server 4.1-mysql Command line client uses the client's shortcut connection

Enter the password set at installation

Basic commands for MySQL (you must have a semicolon at the end of the MySQL command line edit after each input command)

Display database: show databases;

Using database: Use database name;

Build a library

Build a database in MySQL, and a table in the database about

Command: Create database A;

Set permissions for a database (user and password)

Command: Grant all privileges on first.* to Test@localhost identified by "123456";

When you're done with this command, you can only do this with the user name: Test, Password: 123456 When you log on, so that you avoid using the root

Enter command: Use A;

Use of the A-database;

To build a table in the I-Library

Command:

CREATE table about (ID int (8)
Primary key,name varchar (10));


In the table if the data:

Command:

Insert into about values
(' xyw1026 ', ' Laojiang ');


Exit

Command: Exit

JSP connection MySQL

C:\Program files\apache Software Foundation\tomcat5.5\webapps directory to create subdirectories MyApp

Enter the C:\Program files\apache Software Foundation\tomcat5.5\webapps\myapp Directory

Write a file in Notepad to save as first.jsp

The code is as follows:

<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<body>
<%class.forname
("Org.gjt.mm.mysql.Driver"). newinstance ();
String url = "Jdbc:mysql:
Localhost/softforum?user=
Soft&password=soft1234&useunicode=
True&characterencoding=8859_1 "
The name of your database
Connection conn= drivermanager.getconnection (URL);
Statement stmt=conn.createstatement
(Resultset.type_scroll_sensitive,
resultset.concur_updatable);
String sql= "select * from";
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {%>
Your first field content is: <%=rs.getstring (1)%>
The contents of your second field are: <%=rs.getstring (2)%>
<%}%>
<%out.print ("Successful database operation, congratulations");%>
<%rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>


In the browser, enter:

http://127.0.0.1:8080/myapp/first.jsp


If present:

Id|num
0 |laojiang


Database operation successful, congratulations to you, indicates a successful configuration

Enter C:\Program files\apache Software Foundation\tomcat5.5\webapps\myapp Directory

Create a new directory in the MyApp directory Web-inf, note that the directory name is case-sensitive;

Under Web-inf, create a new file with Notepad named Web.xml, which reads as follows:

<?xml version= "1.0" encoding= "Iso-8859-1"?>

<! DOCTYPE Web-app
Public "-//sun Microsystems,
INC.//DTD Web Application 2.3//en "
"target=" _blank ">http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>my Web application</display-name>
<description>
A Application for test.
</description>
</web-app>


Under MyApp, create a new test JSP page with Notepad, the file name is index.jsp, and the file reads as follows:

Now: <%=new java.util.Date ()%>
</center></body
>


Restart Tomcat

Open the browser and enter http://localhost:8080/myapp/index.jsp

When you see the current time, the installation is successful.

To build your own servlet:

Create a new servlet program with Notepad, the file name is Helloworld.java, and the file reads as follows:

Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
{
public void Doget
(HttpServletRequest request
, httpservletresponse response)
Throws Servletexception,ioexception
{

Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
Out.println ("Out.println ("This is the My A-Servlet");
Out.println ("</title>Out.println ("Out.println ("</body>

}
}


Compile

Cut the Helloworld.java to the C:\Program files\apache Software foundation\tomcat5.5\common\classes Directory

Command-Line Input:

CD C:\Program Files\apache Software Foundation
\tomcat5.5\common\classes
Javac Helloworld.java


Use Javac Helloworld.java to compile this file if there is no import javax.servlet.*

Then the C:\Program files\apache Software

Copy of the Servlet-api.jar file in the Foundation\tomcat5.5\common\lib directory and add to

C:\Program Files\java\jre1.5.0_04\lib\ext the catalogue is OK.

And then in C:\Program Files\apache Software

A compiled servlet file is generated under foundation\tomcat5.5\common\classes:

Helloworld.class

Use Notepad to open C:\Program Files\apache Software

The web.xml in the Foundation\tomcat5.5\webapps\root\web-inf directory is shown below, after adding the

The contents are as follows:

<!--jspc servlet mappings Start-->

<servlet>
<servlet-name>org.apache.
Jsp.index_jsp</servlet-name>
<servlet-class>org.apache.
Jsp.index_jsp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>org.apache.
Jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>


<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>

<!--jspc servlet mappings End-->

</web-app>


The servlet section of this passage declares the servlet you want to invoke, while servlet-mapping "maps" the declared servlet to the/servlet/helloworld address.

Start Tomcat, start the browser, enter Http://localhost:8080//servlet/HelloWorld, and if you see output helloworld! The servlet that wrote the instructions was successful. Note: If you have modified the Web.xml and added class, restart Tomcat and you can test it in the directory you created:

Copy Helloworld.class to C:\Program Files\apache Software

The Foundation\tomcat5.5\webapps\myapp\web-inf\classes directory

Where the classes directory does not create a

Use Notepad to open the Web.xml in the C:\Program files\apache Software foundation\tomcat5.5\webapps\myapp\web-inf directory, as shown below, with the following modifications:

<!--jspc servlet mappings Start-->

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/helloworld
</url-pattern>
</servlet-mapping>

<!--jspc servlet mappings End-->

</web-app>


Start Tomcat, start the browser, enter Http://localhost:8080/myapp/servlet/HelloWorld if you see the output helloworld! The servlet that wrote the instructions was successful. Note: If you have modified Web.xml and added class, restart Tomcat and build your own JavaBean:

Create a new Java program with Notepad, the file name is Testbean.java, and the file reads as follows:

Package test;
public class Testbean
{
Private String name = NULL;
Public Testbean (String strname_p)
{
this.name=strname_p;
}
public void SetName (String strname_p)
{
this.name=strname_p;
}
Public String GetName ()
{
return this.name;
}
}


Compile

Place the Testbean.java under C:\Test and compile with the following command:

C:\test>javac Testbean.java


Then a compiled bean file is generated under C:\Test: Testbean.class

Cut the Testbean.class file to C:\Program Files\apache Software

In the Foundation\tomcat5.5\webapps\myapp\web-inf\classes\test directory,

If no subdirectories are created, create a new testbean.jsp file with the following file:

<%@ page import= "test. Testbean "%>
<%
Testbean testbean=new Testbean
("This is a test Java bean.");
%>
Java Bean name is:
<%=testbean.getname ()%>
</center></body>


Restart Tomcat, start the browser, and enter http://localhost:8080/myapp/TestBean.jsp if you see the output Java Bean name Is:this is a test Java bean on the instructions written Javabea N succeeded.



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.