Recent Notes
Displaying notes 121 - 130
Created by Dr. Xi on February 11, 2010 00:04:02
Servlet container initializes this servlet when it starts up. The content of this element must be a positive integer indicating the order in which the servlet should be loaded. Lower integers are loaded before higher integers. If no value is specified, or if the value specified is not a positive integer, the servlet can be loaded in any order in the startup sequence. In this example, Struts is loaded before cms: <!-- Struts action servlet setup --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- All .do requests go to struts --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet> <servlet-name>cms</servlet-name> <servlet-class>com.example.ContentManagementSystem</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <!-- *.cms pages are handled by the cms servlet --> <servlet-name>cms</servlet-name> <url-pattern>*.cms</url-pattern> </servlet-mapping>
Created by Dr. Xi on February 10, 2010 23:48:23
Last update: February 10, 2010 23:49:13
Servlet mapping examples in web.xml. Struts: <!-- Struts action servlet setup --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- All .do requests go to struts --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> Spring: <servlet> <servlet-name>springapp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- All .htm requests go to Spring --> <servlet-mapping> <servlet-name>springapp</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> JSF myfaces: <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- All .faces requests go to JSF --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping>
Created by Dr. Xi on February 10, 2010 23:39:37
Example web.xml that includes most frequently used elements. This sample is for Servlet Specification 2.4. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <!-- Appliocation name and description --> <display-name>Example App</display-name> <description>A web.xml example</description> <!-- Set session timeout to 30 minutes --> <session-config> <session-timeout>30</session-timeout> </session-config> <!-- Context parameters --> <context-param> <description>Enable debugging for the application</description> <param-name>debug</param-name> <param-value>true</param-value> </context-param> <context-param> <description>Web master email</description> <param-name>webmaster</param-name> <param-value>webmaster@example.com</param-value> </context-param> <!-- Servlets --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Servlet mappings --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- Filters --> <filter> <filter-name>loggingFilter</filter-name> <filter-class>com.example.LoggingFilter</filter-class> <init-param> <param-name>appender</param-name> <param-value>com.example.FileAppender</param-value> </init-param> <init-param> <param-name>logging-file</param-name> <param-value>/var/logs/myapp.log</param-value> </init-param> </filter> <!-- Filter mapping --> <filter-mapping> <filter-name>loggingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Application events listener --> <listener> <listener-class>com.example.listener.ContextListener</listener-class> </listener> <!-- Session events listener --> <listener> <listener-class>com.example.listener.SessionListener</listener-class> </listener> ...
Created by meiu on February 10, 2010 20:53:27
Step by step procedure to setup OC4J server for Eclipse. Version used is Galileo for Java EE Developers. Initialize OC4J You'll be asked to create a password the first time you run the standalone OC4J server. You need to remember this password and use it in the Eclipse setup. In the following C:\jdev1013_5 is where the JDeveloper suite is installed. cd C:\jdev1013_5\j2ee\home java -jar oc4j.jar Add Server Runtime Environment Go to Windows menu, bring up the Preferences dialog. Select Server -> Runtime Environments, click Add. Select Oracle OC4J Standalone 10.1.3.n, click Next. Enter J2EE home and click Finish. Add a server for OC4J Go to Windows menu, select Show View -> Servers. If Servers menu is not visible, select Other and enter "servers" in the ...
Created by Dr. Xi on February 09, 2010 04:54:10
Use this to connect to oracle RAC (Real Application Cluster): jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on) (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521)) (ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=service) (FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC) (RETRIES = 180) (DELAY = 5)) )) From Oracle Database JDBC Developer's Guide : Specifier Supported Drivers Example Oracle Net connection descriptor Thin, OCI Thin, using an address list: url="jdbc:oracle:thin:@(DESCRIPTION= (LOAD_BALANCE=on) (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521)) (ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521))) (CONNECT_DATA=(SERVICE_NAME=service_name)))" OCI, using a cluster: "jdbc:oracle:oci:@(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=cluster_alias) (PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=service_name)))" Thin-style service name Thin "jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename" LDAP syntax Thin "jdbc:oracle:thin:@ldap://ldap.example.com:7777/sales,cn=OracleContext,dc=com" Bequeath connection OCI Empty. That is, nothing after @ "jdbc:oracle:oci:scott/tiger/@" TNSNames alias Thin, OCI OracleDataSource ods = new OracleDataSource(); ods.setTNSEntryName("MyTNSAlias");
Created by Dr. Xi on February 09, 2010 03:56:11
Last update: February 09, 2010 04:31:07
From Oracle Database JDBC Developer's Guide : The JDBC Thin client is a pure Java, Type IV driver. It is lightweight and easy to install. It provides high performance, comparable to the performance provided by the JDBC Oracle Call Interface (OCI) driver. The JDBC Thin driver is written entirely in Java, and therefore, it is platform-independent. Also, this driver does not require any additional Oracle software on the client-side. From Java Programming with Oracle JDBC : The important thing to notice about the graph is that it's not until about 65 inserts that the PreparedStatement object outperforms the Statement object. 65 inserts! Clearly, the Statement object is more efficient under typical use when using the OCI driver. you'll see that the Thin driver follows the ...
Created by meiu on February 09, 2010 03:26:14
Last update: February 09, 2010 03:26:44
Simple JDBC code for Oracle. import java.sql.*; public class JDBCHelloWorld { public static void main(String args) throws Exception { Connection conn = null; try { // register Oracle JDBC driver with DriverManager Class.forName("oracle.jdbc.driver.OracleDriver"); // get a connection to the database conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger"); // construct a Statement Statement stmt = conn.createStatement(); // run query ResultSet rs = stmt.executeQuery("SELECT 'Hello World' FROM DUAL;"); // iterate through the result set while (rs.next()) { System.out.println(rs.getString(1)); } } finally { // always close JDBC connection in a finally block! if (conn != null) conn.close(); } } }
Created by voodoo on February 08, 2010 04:57:49
If you don't want to open an extra port for VNC or want extra security with SSH, you can setup an SSH tunnel for VNC. On Windows, you can do this with Putty or openssh . Open a command window, and enter (using Putty as example): C:\local\bin\plink.exe -ssh -2 -L localhost:5901:remote_host:5901 -l username -pw password remote_host -N When connecting with vncviewer , use localhost:5901 as server instead of remote_host:5901 . If you use the setup frequently, it is more convenient to setup the tunnel as a Windows service . Assuming the name of the service is vnc_tunnel , the registry entry would look like: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\vnc_tunnel\Parameters] "Application"="C:\\local\\bin\\plink.exe" "AppDirectory"="C:\\local\\bin" "AppParameters"="-ssh -2 -L localhost:5901:remote_host:5901 -l user_name -pw password remote_host -N"
Created by voodoo on February 08, 2010 04:36:31
Last update: February 08, 2010 05:10:57
If you have X server on the client side, you can run remote desktop with XDMCP . But XDMCP is not secure, and it's somewhat tricky to tunnel XDMCP through ssh. So if you are concerned about security, VNC is a much better choice. Plus vncviewer is a lot easier to set up than X server. There are two options to set up VNC server: VNC vino-server Many Linux distros come with remote desktop server installed. On Fedora Core, you can simply set the configuration from the Desktop menu (Desktop -> Preferences -> Remote Desktop), and use vncviewer from the client machine to access the desktop remotely. Install RealVNC or TightVNC and configure it yourself You need to change ~/.vnc/xstartup in order to see the ...
Created by voodoo on February 07, 2010 23:33:23
Last update: February 08, 2010 03:04:47
I installed vncserver on my Fedora box and tried to connect to it with vncviewer from Windows XP. I got this error: What could be the problem? These were the steps I took to diagnose it. I just list them here as a reminder. Is Windows firewall blocking the connection? No. It turned out that, unlike ZoneAlarm , the Windows firewall does not block outgoing traffic. It only blocks incoming requests. Is vncserver listening on the right IP address? Yes. netstat showed it's listening on all NICs. netstat -a | grep 5901 tcp 0 0 *:5901 *:* LISTEN Is VNC port open on the local Fedora box on that IP address? Yes, telnet successfully connected: [jim@fedora ~] telnet 172.30.33.9 5901 Trying 172.30.33.9... Connected to 172.30.33.9 ...