JSP case analysis (1)-Online Voting System-1-deployment, installation, and debugging

Source: Internet
Author: User

JSP case analysis (1)-Online Voting System-1-deployment, installation, and debugging

Source code: http://download.csdn.net/detail/flyuniverse_shell/4136005

Note: This code is simple and clear, and is a good example of learning.

1. Modify the Tomcat Management User Configuration File
Modify the tomcat-users.xml file, add the administrator role (manager) and administrator user (Admin) and password (Admin) in it, as follows:
<Tomcat-users>
<Role rolename = "manager"/>
<User name = "Tomcat" Password = "Tomcat" roles = "Tomcat"/>
<User name = "role1" Password = "Tomcat" roles = "role1"/>
<User name = "both" Password = "Tomcat" roles = "tomcat, role1"/>
<User Username = "admin" Password = "admin" roles = "manager"/>
</Tomcat-users>

Finally, restart tomcat. when entering the management page, log on to OK with the admin user and password admin.

 
2. Use the sqlserver2008 driver package
Use sqlserver2008 must use the latest driver package, that is, Microsoft SQL Server JDBC driver 2.0, this can be downloaded on the Microsoft official website (http://go.microsoft.com/fwlink? Linkid = 144633 & clcid = 0x804). The downloaded EXE self-extracting file contains two driver packages: sqljdbc. jar and sqljdbc4.jar. As for the differences between the two packages, you can check them online. You only need to select the desired one and put it under the project. At the same time, JDK should use version 5.0 or later.

3. Open Port 2008 of SQL Server 1433
1. Start --> Microsoft SQL Server 2008 --> Configuration tool --> SQL Server Configuration Manager --> Diablo (database instance) Protocol to check whether the TCP/IP protocol is started. If it is started, right-click the menu and choose "properties"

Select "ip address" in the IP address page, set "TCP port" to 1433 in "IP1" and "ip2", and "enabled" to "yes"

2. Start --> Microsoft SQL Server 2008 --> Configuration tool --> SQL Server Configuration Manager --> SQL native Client 10.0 configuration --> client protocol --> TCP/IP
Right-click TCP/IP and choose "properties" from the shortcut menu. Make sure that "Default port" is 1433 and "enabled" is "yes"
Note: Do not start
After completing the preceding operations, restart SQL Server (Diablo) in the SQL Server service ).

How can I check whether port 1433 is listened on?
1. Open the command line (shortcut: Win + R, Enter cmd, and press Enter );

2. Enter netstat and press Enter. If 127.0.0.1: 1433 is not found in the local address bar, port 1433 of sqlserver is not monitored.

4. Modify dB. Java (refer to the following code to modify)
Import java. SQL .*;

Public class connecturl {

Public static void main (string [] ARGs ){

// Create a variable for the connection string.
String connectionurl = "JDBC: sqlserver: // localhost: 1433;" +
"Databasename = adventureworks; user = username; Password = *****";

// Declare the JDBC objects.
Connection con = NULL;
Statement stmt = NULL;
Resultset rs = NULL;

Try {
// Establish the connection.
Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdriver ");
Con = drivermanager. getconnection (connectionurl );

// Create and execute an SQL statement that returns some data.
String SQL = "select top 10 * from person. Contact ";
Stmt = con. createstatement ();
Rs = stmt.exe cutequery (SQL );

// Iterate through the data in the result set and display it.
While (Rs. Next ()){
System. Out. println (Rs. getstring (4) + "" + Rs. getstring (6 ));
}
}

// Handle any errors that may have occurred.
Catch (exception e ){
E. printstacktrace ();
}
Finally {
If (RS! = NULL) Try {Rs. Close ();} catch (exception e ){}
If (stmt! = NULL) Try {stmt. Close ();} catch (exception e ){}
If (con! = NULL) Try {con. Close ();} catch (exception e ){}
}
}
}

5. If you deploy the project in myeclipse, There is only an empty lib folder under the WEB-INF folder under Tomcat webapps, the solution is:
Create a workspace
File-> switch Workspace-> Other-> browse select a new workspace.

6. When deploying in myeclipse, place the CSS and images folders under webroot.

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.