jsp案例分析(一)-在线投票系统-1-部署安装调试

这是一个关于jsp的在线投票系统案例,提供了详细的部署、安装和调试步骤。通过源代码分析,适合初学者学习实践。
摘要由CSDN通过智能技术生成
jsp案例分析(一)-在线投票系统-1-部署安装调试

源代码:http://download.csdn.net/detail/flyuniverse_shell/4136005


说明:本代码简单明了,是学习的好例子。


1、修改tomcat管理用户配置文件
修改tomcat-users.xml文件,在其中添加管理员角色(manager),以及管理员用户(admin)和密码(admin),修改后如下:
<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>


最后,重启tomcat,在进入管理页面的时候,用管理员用户admin和密码admin,登陆ok。


 
2、使用sqlserver2008驱动包
使用SqlServer2008必须用到最新的驱动包,即Microsoft SQL Server JDBC Driver 2.0,这个可以到微软官网上下载(http://go.microsoft.com/fwlink/?LinkId=144633&clcid=0x804),下载下来的是个exe自解压文件,里面包括两个驱动包:sqljdbc.jar和sqljdbc4.jar。至于这两个包的区别,网上一查便知,在此不必多说,只需要选择需要的一个放到项目下就可以了,同时JDK要用5.0及以上的版本。


3、打开SQL Server 2008的1433端口
1、开始——>Microsoft SQL Server 2008——>配置工具——>Sql Server 配置管理器——>DIABLO(数据库实例)的协议中看看TCP/IP协议是否启动,如果启动,右键菜单点"属性" 


,在IP地址页菜单中选"IP地址",把"IP1"和"IP2"中"TCP端口"为1433,"已启用"改为"是"


2、开始——>Microsoft SQL Server 2008——>配置工具——>Sql Server 配置管理器——>SQL Native Client 10.0 配置——>客户端协议——>TCP/IP
选择TCP/IP右键菜单中"属性",确认"默认端口"是1433,"已启用"为"是"
注意:不要启动VIA
以上操作完成后,在SQL Server 服务中重启SQL Server (DIABLO)。


如何查看1433端口是否被监听?
 1.打开命令行(快捷键win+r,输入cmd,回车);


 2.输入netstat,回车;如果其中本地地址栏里没有127.0.0.1:1433,则说明SqlServer的1433端口未被监听.


4、修改DB.java(参照下面代码修改)
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.executeQuery(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、如果在MyEclipse里部署工程,在tomcat的webapps下只有WEB-INF文件夹 WEB-INF下有一个空的lib文件夹,解决办法是:
新建一个WorkSpace
File->Switch WorkSpace->other->Browse选择新的工作区。


6、在myeclipse中部署时,将css和images文件夹放在WebRoot下。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值