I have searched the internet for many times and found that there are few examples of jsp + sqlserver2000 project development. In Tomcat 5, configure the server. xml becomes a problem because many mysql and oracle configuration examples are available on tomcat websites, but few SQL Server Examples are available.
Today, I will share my research experience. This is deployed on linux.
This article tells you how to configure server. xml so that you can smoothly read the sqlserver database. For details about how to use struts and hibernate, refer to the relevant website materials.
First, you need to download sqlserver's java patch package on the Microsoft website. After the patch is unpatched, copy the three mssqlserver. jar msbase. jar msutil. jar files to the WEB-LIB/lib directory;
Then configure server. xml as follows: (Note that you need to change the Chinese character in it)
<? Xml version = '1. 0' encoding = 'utf-8'?>
<Server>
<Listener className = "org. apache. catalina. mbeans. ServerLifecycleListener"/>
<Listener className = "org. apache. catalina. mbeans. GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>
<Environment name = "simpleValue" type = "java. lang. Integer" value = "30"/>
<Resource auth = "Container" description = "User database that can be updated and saved" name = "UserDatabase" type = "org. apache. catalina. UserDatabase"/>
<ResourceParams name = "UserDatabase">
<Parameter>
<Name> factory </name>
<Value> org. apache. catalina. users. MemoryUserDatabaseFactory </value>
</Parameter>
<Parameter>
<Name> pathname </name>
<Value> conf/tomcat-users.xml </value>
</Parameter>
</ResourceParams>
</GlobalNamingResources>
<Service name = "Catalina">
<Connector acceptCount = "100" connectionTimeout = "20000" disableUploadTimeout = "true" port = "80" redirectPort = "8443">
</Connector>
<Connector port = "8009" protocol = "AJP/1.3" protocolHandlerClassName = "org. apache. jk. server. JkCoyoteHandler" redirectPort = "8443">
</Connector>
<Engine defaultHost = "write the host name here, for example, bbs in bbs.abc.com" name = "Catalina">
<Host name = "Enter the domain name here, for example," debug = "0" appBase = "Enter the absolute path of the web directory/opt/tomcat/webapps/abc" in www.abc.com"
UnpackWARs = "true" autoDeploy = "true">
<Valve className = "org. apache. catalina. valves. AccessLogValve"
Directory = "logs" prefix = "sentom1_access_log." suffix = ". txt"
Pattern = "common" resolveHosts = "false"/>
<Logger className = "org. apache. catalina. logger. FileLogger"
Directory = "logs" prefix = "sentomw.log." suffix = ". txt"
Timestamp = "true"/>
<Context path = "" docBase = "">
<Resource name = "write the jndi join here, for example, jdbc/abc" scope = "Shareable" auth = "Container" type = "write the class used by ms sqlserver Database: com. microsoft. jdbcx. sqlserver. SQLServerDataSource "/>
<ResourceParams name = "write the jndi connection here, for example, jdbc/abc">
<Parameter>
<Name> factory </Name>
<Value> com. Microsoft. jdbcx. sqlserver. sqlserverperformancefactory </value>
</Parameter>
<! -- DBCP database connection settings -->
<Parameter>
<Name> driverclassname </Name> <value> com. Microsoft. jdbcx. sqlserver. sqlserverdatasource </value>
</Parameter>
<Parameter> <Name> drivername </Name> <value> sqlserver </value> </parameter>
<Parameter> <Name> description </Name> <value> SQL Server datasource </value> </parameter>
<Parameter> <Name> servername </Name> <value> write the Server IP address here </value> </parameter>
<Parameter> <Name> portnumber </Name> <value> write the sqlserver port number here. Generally, write 1433 </value> </parameter>
<Parameter> <Name> selectmethod </Name> <value> cursor </value> </parameter>
<Parameter> <Name> databasename </Name> <value> name of the database used by sqlserver </value> </parameter>
<Parameter> <name> user </name> <value> the user name in the sqlserver database is written here. You must have read and write permissions on the relevant database </value> </parameter>
<Parameter> <name> password </name> <value> write the password here </value> </parameter>
<Parameter> <name> loginTimeout </name> <value> 3000 </value> </parameter>
<! -- DBCP connection pooling options -->
<Parameter> <name> maxWait </name> <value> 3000 </value> </parameter>
<Parameter> <name> maxIdle </name> <value> 100 </value> </parameter>
<Parameter> <name> maxActive </name> <value> 10 </value> </parameter>
</ResourceParams>
</Context>
</Host>
You can write another second-level website to read another database.
<Host name = "enter the second-level website domain name here. For example: news.abc.com "debug =" 0 "appBase =" the absolute path of the web directory/opt/tomcat/webapps/news"
UnpackWARs = "true" autoDeploy = "true">
<Valve className = "org. apache. catalina. valves. AccessLogValve"
Directory = "logs" prefix = "sentom1_access_log." suffix = ". txt"
Pattern = "common" resolveHosts = "false"/>
<Logger className = "org. apache. catalina. logger. FileLogger"
Directory = "logs" prefix = "sentomw.log." suffix = ". txt"
Timestamp = "true"/>
<Context path = "" docBase = "">
<Resource name = "Enter the jndi name: jdbc/news" scope = "retriable" auth = "Container" type = "com. microsoft. jdbcx. sqlserver. SQLServerDataSource"/>
<ResourceParams name = "Enter the jndi name: jdbc/news">
<Parameter>
<Name> factory </name>
<Value> com. microsoft. jdbcx. sqlserver. sqlserverperformancefactory </value>
</Parameter>
<! -- DBCP database connection settings -->
<Parameter>
<Name> driverClassName </name> <value> com. microsoft. jdbcx. sqlserver. SQLServerDataSource </value>
</Parameter>
<Parameter> <name> driverName </name> <value> SQLServer </value> </parameter>
<Parameter> <name> description </name> <value> SQL Server DataSource </value> </parameter>
<Parameter> <name> serverName </name> <value> database IP address </value> </parameter>
<Parameter> <name> portNumber </name> <value> port: 1433 </value> </parameter>
<Parameter> <name> selectMethod </name> <value> cursor </value> </parameter>
<Parameter> <name> databaseName </name> <value> database name </value> </parameter>
<Parameter> <name> user </name> <value> user name </value> </parameter>
<Parameter> <name> password </name> <value> password </value> </parameter>
<Parameter> <name> loginTimeout </name> <value> 3000 </value> </parameter>
<! -- DBCP connection pooling options -->
<Parameter> <name> maxWait </name> <value> 3000 </value> </parameter>
<Parameter> <Name> maxidle </Name> <value> 100 </value> </parameter>
<Parameter> <Name> maxactive </Name> <value> 10 </value> </parameter>
</Resourceparams>
</Context>
</Host>
<Host appbase = "webapps" name = "localhost">
<Logger classname = "org. Apache. Catalina. Logger. filelogger" prefix = "localhost_log." suffix = ". txt" timestamp = "true"/>
</Host>
<Host name = "another host name can be written here, for example, www" appbase = "/opt/tomcat/webapps/www">
<! -- Alias> www.spitrade.com </alias -->
</Host>
<Logger className = "org. apache. catalina. logger. FileLogger" prefix = "catalina_log." suffix = ". txt" timestamp = "true"/>
<Realm className = "org. apache. catalina. realm. UserDatabaseRealm"/>
</Engine>
</Service>
</Server>
Then configure hibernate. cfg. xml (as follows ):
Note that the java: comp/env/jdbc/news parameter must be consistent with the ResourceParams Parameter Related to jndi in server. xml.
<? Xml version = '1. 0' encoding = 'utf-8'?>
<! DOCTYPE hibernate-configuration
PUBLIC "-// Hibernate/Hibernate Configuration DTD // EN"
Http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd>
<Hibernate-configuration>
<Session-factory>
<Property name = "connection. datasource"> java: comp/env/jdbc/news </property>
<Property name = "show_ SQL"> true </property>
<Property name = "dialect"> net. sf. hibernate. dialect. SQLServerDialect </property>
<! -- Mapping files -->
<Mapping resource = "News. hbm. xml"/>
</Session-factory>
</Hibernate-configuration>
Now, the configuration is successful.
If you have any questions, please discuss them.