|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
C++编译的是本地码,优点是启动快,而且可以精确控制资源因此可以开发很高效的程序.缺点是编程麻烦,而且容易留下安全隐患.跨平台靠源代码在各个平台间分别编译(一处编写到处编译)mysql筹办情况:
1.j2sdk-1_4_2-windows-i586.exe
//jdk
2.mysql-4.0.20d-win.zip
//mysql数据库
3.mysqlcc-0.9.4-win32.zip
//mysqlGUI把持
4.jakarta-tomcat-5.0.27.exe
//tomcat服务器
5.mysql-connector-java-3.0.14-production.zip
//内含mysql驱动
安装步骤:
1.安装jdk
2.安装tomcat
3.安装mysql
4.安装mysqlcc
5.将驱动包解压,拷贝mysql-connector-java-3.0.14-production-bin.jar
到tomcat/common/lib下
大概下载mm.mysql-2.0.14-you-must-unjar-me.jar,
解压后拷贝个中的mm.mysql-2.0.14-bin.jar
Tomcat5.0设置本例利用安装暗码198277
1.设置manager办理使用程序
在conf/server.xml中
增加以下:
- <Servicename="Catalina">...<Contextpath="/manager"debug="0"privileged="true"docBase="/usr/local/kinetic/tomcat5/server/webapps/manager"></Context></Service>
复制代码
限定IP会见设置
- <Contextpath="/manager"debug="0"privileged="true"docBase="/usr/local/kinetic/tomcat5/server/webapps/manager"><ValveclassName="org.apache.catalina.valves.RemoteAddrValve"allow="127.0.0.1"/></Context>
复制代码
测试为:http://localhost:8080/manager/html
2、设置JDBCRealm容器办理平安,以mysql-4.0数据库为例
a.拷贝驱动mm.mysql-2.0.14-bin.jar到common/lib/下
b.在数据库ycg中建表
- createtableusers(user_namevarchar(15)notnullprimarykey,user_passvarchar(15)notnull);createtableuser_roles(user_namevarchar(15)notnull,role_namevarchar(15)notnull,primarykey(user_name,role_name));
复制代码
c.修正server.xml以下(默许数据库为root,无暗码,假如无形如:
- connectionURL="jdbc:mysql://localhost/authority?user=dbuser&password=dbpass")<RealmclassName="org.apache.catalina.realm.JDBCRealm"debug="99"driverName="org.gjt.mm.mysql.Driver"connectionURL="jdbc:mysql://localhost/ycg?user=root"connectionName=""connectionPassword=""userTable="users"userNameCol="user_name"userCredCol="user_pass"userRoleTable="user_roles"roleNameCol="role_name"/>
复制代码
d.在数据库中增加进tomcat的默许设置数据:
e.启动mysql,启动tomcat,今后tomcat将从数据库中读用户划定规矩认证.默许的conf/tomcat-users.xml生效
3.DBCP的设置
a.设置
- <parameter><name>removeAbandoned</name><value>true</value></parameter>
复制代码
可以使生效的数据毗连从头启用.
配套设置
- <parameter><name>removeAbandonedTimeout</name><value>60</value></parameter>
复制代码
生效工夫
假如要写进日记
设置
- <parameter><name>logAbandoned</name><value>true</value></parameter>
复制代码
以上三个默许都是false
b.以mysql为例,设置数据毗连池
c.设置新的用户与数据库,必需设定暗码,空暗码将招致毗连失利
e.
指定root暗码:
- mysqladmin-uroot-hlocalhostpassword"198277"
复制代码
(需修正下面的jdbcrealm设置connectionURL="jdbc:mysql://localhost/ycg?user=root&password=198277")
命令mysql进进匿名毗连到服务器
暗码会见
- shell>mysql-hhost-uuser-pEnterpassword:********//假如root没有暗码,以下是不乐成的.(试过了)mysql>GRANTALLPRIVILEGESON*.*TOjavauser@localhost->IDENTIFIEDBYjavadudeWITHGRANTOPTION;mysql>createdatabasejavatest;mysql>usejavatest;mysql>createtabletestdata(->idintnotnullauto_incrementprimarykey,->foovarchar(25),->barint);在conf/server.xml中<host></host>中增加<Contextpath="/DBTest"docBase="DBTest"debug="5"reloadable="true"crossContext="true"><LoggerclassName="org.apache.catalina.logger.FileLogger"prefix="localhost_DBTest_log."suffix=".txt"timestamp="true"/><Resourcename="jdbc/TestDB"auth="Container"type="javax.sql.DataSource"/><ResourceParamsname="jdbc/TestDB"><parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter><!--MaximumnumberofdBconnectionsinpool.Makesureyouconfigureyourmysqldmax_connectionslargeenoughtohandleallofyourdbconnections.Setto0fornolimit.--><parameter><name>maxActive</name><value>100</value></parameter><!--MaximumnumberofidledBconnectionstoretaininpool.Setto0fornolimit.--><parameter><name>maxIdle</name><value>30</value></parameter><!--MaximumtimetowaitforadBconnectiontobecomeavailableinms,inthisexample10seconds.AnExceptionisthrownifthistimeoutisexceeded.Setto-1towaitindefinitely.--><parameter><name>maxWait</name><value>10000</value></parameter><!--MySQLdBusernameandpasswordfordBconnections--><parameter><name>username</name><value>javauser</value></parameter><parameter><name>password</name><value>javadude</value></parameter><!--Classnamefortheoldmm.mysqlJDBCdriver-uncommentthisentryandcommentnextifyouwanttousethisdriver-werecommendusingConnector/Jthough<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value></parameter>--><!--ClassnamefortheofficialMySQLConnector/Jdriver--><parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter><!--TheJDBCconnectionurlforconnectingtoyourMySQLdB.TheautoReconnect=trueargumenttotheurlmakessurethatthemm.mysqlJDBCDriverwillautomaticallyreconnectifmysqldclosedtheconnection.mysqldbydefaultclosesidleconnectionsafter8hours.--><parameter><name>url</name><value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value></parameter><parameter><name>removeAbandoned</name><value>true</value></parameter><parameter><name>removeAbandonedTimeout</name><value>60</value></parameter><parameter><name>logAbandoned</name><value>true</value></parameter></ResourceParams></Context>
复制代码
f.在web服务中挪用.设置web.xml如:
- <web-appxmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4"><description>MySQLTestApp</description><resource-ref><description>DBConnection</description><res-ref-name>jdbc/TestDB</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref></web-app>
复制代码
g.测试用test.jsp
- <%@tagliburi="http://java.sun.com/jsp/jstl/sql"prefix="sql"%><%@tagliburi="http://java.sun.com/jsp/jstl/core"prefix="c"%><sql:queryvar="rs"dataSource="jdbc/TestDB">selectid,foo,barfromtestdata</sql:query><html><head><title>DBTest</title></head><body><h2>Results</h2><c:forEachvar="row"items="${rs.rows}">Foo${row.foo}<br/>Bar${row.bar}<br/></c:forEach></body></html>
复制代码
h.新建web使用
下载jakarta-taglibs-standard-1.1.0
copyjstl.jarandstandard.jartoyourwebappsWEB-INF/lib
- DBTest/WEB-INF/web.xmllib/jstl.jarstandard.jartest.jsp
复制代码
拷贝到webapps/下
i.启动mysql,tomcat
会见:
http://localhost:8080/DBTest/test.jsp
显现:
4.ssl的设置,以jdk1.4.2为例
a.进进%JAVA_HOME%in
运转命令:keytool-genkey-aliastomcat-keyalgRSA
以tomcat安装暗码为198277,ketool设置暗码为198277为例
输出keystore暗码:198277
您的名字与姓氏是甚么?
[Unknown]:ycg
您的构造单元称号是甚么?
[Unknown]:nju
您的构造称号是甚么?
[Unknown]:nju
您地点的乡村或地区称号是甚么?
[Unknown]:nanjing
您地点的州或省分称号是甚么?
[Unknown]:jiangsu
该单元的两字母国度代码是甚么
[Unknown]:nd
CN=ycg,OU=nju,O=nju,L=nanjing,ST=jiangsu,C=nd准确吗?
[否]:y
输出的主暗码
(假如和keystore暗码不异,按回车):198277
b.在你的D:DocumentsandSettings确当前用户目次下能够找到.keystore文件.将其拷贝到conf/文件夹下.
c.在server.xml中找到
- <!--<Connectorport="8443"maxThreads="150"minSpareThreads="25"maxSpareThreads="75"enableLookups="false"disableUploadTimeout="true"acceptCount="100"debug="0"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"/>-->
复制代码
往失落正文
增加设置字段:keystoreFile="/conf/.keystore"keystorePass="198277"
如:
- <Connectorport="8443"maxThreads="150"minSpareThreads="25"maxSpareThreads="75"enableLookups="false"disableUploadTimeout="true"acceptCount="100"debug="0"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"keystoreFile="/conf/.keystore"keystorePass="198277"/>
复制代码
d.测试为:
https://localhost:8443
e.在本人的程序中增加ssl认证体例为:
在web.xml中增加
- <security-constraint><web-resource-collection><web-resource-name>Success</web-resource-name><url-pattern>/</url-pattern><http-method>GET</http-method><http-method>POST</http-method></web-resource-collection><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint>
复制代码
f.用上提为例就是
修正web.xml为
- <web-appxmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4"><description>MySQLTestApp</description><security-constraint><web-resource-collection><web-resource-name>Success</web-resource-name><url-pattern>/</url-pattern><http-method>GET</http-method><http-method>POST</http-method></web-resource-collection><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint><resource-ref><description>DBConnection</description><res-ref-name>jdbc/TestDB</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref></web-app>
复制代码
会见:
https://localhost:8443/DBTest/test.jsp
g.假如与2设置的jdbcRealm分离起来举行表单认证
先在user_roles表中增加user_name:ycgrole_name:web-user
在users表中增加user_name:ycguser_pass:198277
然后在web.xml中增加
- <auth-constraint><role-name>web-user</role-name></auth-constraint><login-config><auth-method>BASIC</auth-method><realm-name>MyMemberArea</realm-name></login-config>
复制代码
修正后的web.xml如:
- <web-appxmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4"><description>MySQLTestApp</description><security-constraint><web-resource-collection><web-resource-name>Success</web-resource-name><url-pattern>/</url-pattern><http-method>GET</http-method><http-method>POST</http-method></web-resource-collection><auth-constraint><role-name>web-user</role-name></auth-constraint><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint><login-config><auth-method>BASIC</auth-method><realm-name>MyMemberArea</realm-name></login-config><resource-ref><description>DBConnection</description><res-ref-name>jdbc/TestDB</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref></web-app>
复制代码
测试:
http://localhost:8080/DBTest/test.jsp
将经由过程ssl毗连,并举行表单认证.用户暗码可在user_roles,和users中增加.
5.中文乱码成绩:
mysql默许编码iso
tomcatrequest传输编码iso
假如要显现中文
在*.jsp中增加
- <head><%@pagelanguage="java"contentType="text/html;charset=GB18030"pageEncoding="GB18030"%></head>
复制代码
假如是数据传输中的乱码(如用servlet从mysql数据库读出的数据)用以下两个转码函数转码,假如不分明由哪一种编码转成哪一种编码,就多实验。
- //转码GBK转ISOpublicStringtoISO(Stringinput){try{byte[]bytes=input.getBytes("GBK");returnnewString(bytes,"ISO8859-1");}catch(Exceptionex){}returninput;}//转码IS0转GBKpublicStringtoGBK(Stringinput){try{byte[]bytes=input.getBytes("ISO8859-1");returnnewString(bytes,"GBK");}catch(Exceptionex){}returninput;}
复制代码 用winrar打包j2ee的程序和用IDE打包应用程序是一样的。按照你的想法,你是不是也希望服务器都整合由一家公司提供呢? |
|