Sun River
Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
posts - 78,comments - 0,trackbacks - 0

Question How do you delete a Cookie within a JSP? (JSP)

Answer

Cookie mycook = new Cookie("name","value");

response.addCookie(mycook);

Cookie killmycook = new Cookie("mycook","value");

killmycook.setMaxAge(0);

killmycook.setPath("/");

killmycook.addCookie(killmycook);

Question How many types of protocol implementations does RMI have? (RMI)

Answer RMI has at least three protocol implementations: Java

Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP),

and Jini Extensible Remote Invocation(JERI). These are alternatives,

not part of the same thing, All three are indeed layer 6 protocols for

those who are still speaking OSI reference model.

Question What are the different identifier states of a Thread?

(Core Java)

Answer The different identifiers of a Thread are:

R - Running or runnable thread

S - Suspended thread

CW - Thread waiting on a condition variable

MW - Thread waiting on a monitor lock

MS - Thread suspended waiting on a monitor lock


Question What is the fastest type of JDBC driver? (JDBC)

Answer JDBC driver performance will depend on a number of

issues:

(a) the quality of the driver code,

(b) the size of the driver code,

(c) the database server and its load,

(d) network topology,

(e) the number of times your request is translated to a different API.

In general, all things being equal, you can assume that the more your

request and response change hands, the slower it will be. This

means that Type 1 and Type 3 drivers will be slower than Type 2

drivers (the database calls are make at least three translations versus

two), and Type 4 drivers are the fastest (only one translation).

Question Request parameter How to find whether a parameter

exists in the request object? (Servlets)

Answer 1.boolean hasFoo = !(request.getParameter("foo") ==

null || request.getParameter("foo").equals(""));

2. boolean hasParameter =

request.getParameterMap().contains(theParameter);

(which works in Servlet 2.3+)


Question How can I send user authentication information while

makingURLConnection? (Servlets)

Answer You’ll want to use

HttpURLConnection.setRequestProperty and set all the appropriate

headers to HTTP authorization.

Question How do I convert a numeric IP address like 192.18.97.39

into a hostname like java.sun.com? (Networking)

Answer

Question How many methods do u implement if implement the

Serializable Interface? (Core Java)

Answer The Serializable interface is just a "marker" interface,

with no methods of its own to implement. Other ’marker’ interfaces

are

java.rmi.Remote

java.util.EventListener

String hostname =InetAddress.getByName("192.18.97.39").getHostName();

posted @ 2010-10-25 17:08 Sun River| 编辑 收藏
1.

Question What is the query used to display all tables names in

SQL Server (Query analyzer)? (JDBC)

Answer select * from information_schema.tables

Question What is Externalizable? (Core Java)

Answer Externalizable is an Interface that extends Serializable

Interface. And sends data into Streams in Compressed Format. It has

two methods, writeExternal(ObjectOuput out) and

readExternal(ObjectInput in).

Question What modifiers are allowed for methods in an Interface?

Answer Only public and abstract modifiers are allowed for

methods in interfaces.

Question How many types of JDBC Drivers are present and what

are they? (JDBC)

Answer There are 4 types of JDBC Drivers

Type 1: JDBC-ODBC Bridge Driver

Type 2: Native API Partly Java Driver

Type 3: Network protocol Driver

Type 4: JDBC Net pure Java Driver

Question What is the difference between ServletContext and

PageContext? (JSP)

Answer ServletContext: Gives the information about the container

PageContext: Gives the information about the Request.

Question How to pass information from JSP to included JSP?

Answer Using <%jsp:param> tag.

posted @ 2010-10-25 16:07 Sun River| 编辑 收藏

 

tomcat6配置双向认证

1
、生成服务器端证书

keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=beijing,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650


2
、生成客户端证书

keytool -genkey -keyalg RSA -dname "cn=sango,ou=sango,o=none,l=china,st=beijing,c=cn" -alias custom -storetype PKCS12 -keypass password -keystore custom.p12 -storepass password -validity 3650


客户端的CN可以是任意值。
3
、由于是双向SSL认证,服务器必须要信任客户端证书,因此,必须把客户端证书添加为服务器的信任认证。由于不能直接将PKCS12格式的证书库导入,我们必须先把客户端证书导出为一个单独的CER文件,使用如下命令,先把客户端证书导出为一个单独的cer文件:

keytool -export -alias custom -file custom.cer -keystore custom.p12 -storepass password -storetype PKCS12 -rfc


然后,添加客户端证书到服务器中(将已签名数字证书导入密钥库)

keytool -import -v -alias custom -file custom.cer -keystore server.jks -storepass password


4
、查看证书内容

keytool -list -v -keystore server.jks -storepass password


5
、配置tomcat service.xml文件

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="true" sslProtocol="TLS"
    keystoreFile="D:/server.jks" keystorePass="password"
    truststoreFile="D:/server.jks" truststorePass="password"
/>


clientAuth="true"
表示双向认证
6
、导入客户端证书到浏览器
双向认证需要强制验证客户端证书。双击“custom.p12”即可将证书导入至IE

tomcat6
配置单向认证

1
、生成服务器端证书

keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=beijing,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650


2
、由于是单向认证,没有必要生成客户端的证书,直接进入配置tomcat service.xml文件

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    keystoreFile="D:/server.jks" keystorePass="password"    
/>


clientAuth="false"
表示单向认证,同时去掉truststoreFile="D:/server.jks" truststorePass="password"2

posted @ 2010-05-11 12:12 Sun River| 编辑 收藏