Recent Notes
Displaying notes 111 - 120
Created by Dr. Xi on February 18, 2010 20:39:59
Last update: February 18, 2010 20:41:17
Oracle provides two functions for string replacement: REPLACE and TRANSLATE . REPLACE replaces one substring with another: -- Replace John with Bob select REPLACE('Hello John', 'John', 'Bob') from dual; -- Match is case sensitive, lower case john won't match select REPLACE('Hello John', 'john', 'Bob') from dual; TRANSLATE replaces one character by another, position for position: -- rot13 in Oracle SQL select TRANSLATE('Hello John', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm') from dual; -- Remove all question marks select TRANSLATE('How? are? you?', '.?', '.') from dual; -- This does not work! select TRANSLATE('How? are? you?', '?', '') from dual;
Created by Dr. Xi on February 15, 2010 06:09:56
Last update: February 16, 2010 03:08:34
The context root of a web application determines the root path of URLs that will be handled by that application. For example, if the context root is example , then URLs starting with /example (i.e., /example/* ) will be handled by that application. By default, Tomcat uses the WAR file name (without the .war extension) or, if deployed in exploded directory form, the name of the top level directory as the context root . For example, the pre-installed examples application is deployed under the examples directory under webapps , and its context root is examples . You may want to use a different context root than Tomcat's default. For example, if you build your application with Maven, the resulting WAR file might be named my-fabulous-app-1.0-SNAPSHOT.war ...
Created by Dr. Xi on February 14, 2010 23:00:53
Last update: February 16, 2010 03:20:24
Tomcat auto-deploys WAR files or exploded web applications copied to the appBase directory by default. The default Host configuration in server.xml looks like this: <!-- Define the default virtual host Note: XML Schema validation will not work with Xerces 2.2. --> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> So the appBase directory is named webapps by default, which is where the manager and examples applications are. You can deploy a new application by dropping your WAR file, or copying your application in exploded WAR structure to the same directory. Your application is automatically re-deployed when a new WAR file is copied to webapps , or, in exploded structure, WEB-INF/web.xml is updated. The reason that Tomcat knows to reload a web application when web.xml is updated ...
Created by Dr. Xi on February 13, 2010 22:52:18
This runtime error happens when the Sun EL implementation is not available. Look for the class com.sun.el.ExpressionFactoryImpl in your deployment package, you probably won't find it, or you'll find a version that can't be loaded in your deployment environment. If you are using Maven to build, you can add the following repository and dependency in pom.xml : <!-- Project dependencies --> <dependencies> <dependency> <groupId>com.sun.el</groupId> <artifactId>el-ri</artifactId> <version>1.0</version> <scope>runtime</scope> </dependency> </dependencies> <repositories> <!-- Repository for EL --> <repository> <id>maven2-repository.dev.java.net</id> <name>Java.net Repository for Maven</name> <url>http://download.java.net/maven/2/</url> <layout>default</layout> </repository> </repositories>
Created by Dr. Xi on February 12, 2010 23:07:08
Run $CATALINA_HOME/bin/service.bat to install Tomcat as a Windows service. The default service name is Tomcat6 for Tomcat 6. I like to use all lower cases 'cause I don't want to remember mixed cases. cd %CATALINA_HOME% bin\service install tomcat6 To remove the service: cd %CATALINA_HOME% bin\service remove tomcat6 To start or stop the service: net start tomcat6 net stop tomcat6
Created by Dr. Xi on February 12, 2010 22:52:27
For Tomcat 6, there's no default manager username and password. You do have to set it up yourself, though it's pretty straightforward. The Tomcat manager webapp is restricted to users with a role named manager . So you'll need to create a user and assign the manager role to it. Edit $CATALINA_BASE/conf/tomcat-users.xml to read: <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required ...
Created by Dr. Xi on February 12, 2010 22:39:15
When you start Tomcat for the first time, you may get the "port 8080 is already in use" error. Indeed, port 8080 is commonly used by a lot of development servers by default (Oracle XE for another example). Luckily, it's quite easy to ask Tomcat to use a different port. I use port 8086, which is a natural next step and superior to 8080. Simply edit $CATALINA_BASE/conf/server.xml and change 8080 to 8086: <!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : Java HTTP Connector: /docs/config/http.html (blocking & non-blocking) Java AJP Connector: /docs/config/ajp.html APR (HTTP/AJP) Connector: /docs/apr.html Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector port="8086" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> If you have not configured ...
Created by Dr. Xi on February 11, 2010 05:07:48
Last update: February 11, 2010 05:08:20
On Linux, you can use the fuser command to find out who has a file open, or is using a port. For example, if you start Tomcat and get the error "Address already in use: 8080", you want to know which process is already binding to port 8080. # list processes on port 8080 fuser 8080/tcp # verbose mode fuser -v 8080/tcp # kill the processes accessing port 8080 fuser -k 8080/tcp # show all processes at the (local) TELNET port fuser telnet/tcp # list processes using /mnt/usb1 with user name fuser -m -u /mnt/usb1 # list process IDs and user names for processes using the current directory fuser -fu .
Created by meiu on February 11, 2010 04:34:48
Bring up the System Properties dialog by pressing Windows Logo + Pause/Break . Select the Advanced tab. Click the "Environment Variables" button. Create a new environment variable by clicking New . Edit an existing one by clicking Edit . User specific variables are on the top. System wide variables (effective for all users) are at the bottom.
Created by Dr. Xi on February 11, 2010 00:39:57
The <taglib> element is no longer needed in web.xml since JSP 2.0. Since the location of TLD files are not specified, the servlet container searches for them in these places: Under the /WEB-INF folder Sub folders of the /WEB-INF folder Inside JAR files under /WEB-INF/lib - in the META-INF folder inside the JAR. Usually the TLD files are packaged with the tag library class files in the same JAR. For example, the TLD files for the standard JSTL tags can be found in standard.jar/META-INF . How do you use a custom tag in a JSP then? You use the same uri as declared in the TLD in the taglib declaration of your JSP. For example, the JSTL core tags TLD ( c.tld ) looks like ...