Throughout the web, there are a lot of articles configured in Tomcat, and there are few articles dedicated to how to configure them in a project. So, how do you configure it in your project?
As you all know, eclipse will automatically put the project in the workspace. Some say, then configure the. Server in workspace, and then configure the project. However, I do not know whether the RP problem, the author as long as the right. Server.xml under the server, running Tomcat will make an error.
So, we're going to have to configure it separately in the project.
First, under the workspace/project name/webcontent/meta-inf establishes Context.xml, the content is:
<?xml version= ' 1.0 ' encoding= ' utf-8 '?> <Context> <watchedresource>web-inf/web.xml</ watchedresource> <resource name= "Jdbc/sqlserver" auth= "Container" type= "Javax.sql.DataSource" maxactive= "100" maxidle= "maxwait=" 10000 "username=" sa "password=" ******* "Driverclassname=" Com.microsoft.jdbc.sqlserver.SQLServerDriver "Url=" Jdbc:microsoft:sqlserver://localhost:1433;databasename=book " /> <resourcelink name= "jdbc/sqlserver" global= "Jdbc/sqlserver" type= "Javax.sql.DataSource"/> </context >
Then, modify the Web.xml under the workspace/project name/webcontent/web-inf to:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id= "Webapp_ ID "version=" 2.5 "> <display-name>MyDemo1</display-name> <welcome-file-list> <welcome-file >index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file> Index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file> Default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <resource-ref> <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&Gt
Then, write a JSP page test, index.jsp
<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%> <% @page import=" java.sql.*,javax.sql.*,javax.naming.* "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Remember to place the three drive packs that connect MS SQL Server to the project's Lib and to Tomcat 6.0 's lib.