Recent Notes

Displaying keyword search results 1 - 11
Created by Dr. Xi on April 19, 2012 10:10:08    Last update: April 19, 2012 10:11:06
The default servlet for Tomcat is declared in $CATALINA_HOME/conf/web.xml : <servlet> <servlet-name>default</servle... Therefore, static content is rendered by the default configuration unless you override it with your own definitions. If you want to allow directory listing, just change the listing parameter to true : <init-param> <param-name>listings</para... Change the welcome-file-list to display a default page in lieu of a directory listing: <welcome-file-list> <welcome-file>home.xhtml</... Welcome pages are defined at the Web application level.
Created by venky on March 05, 2012 13:36:41    Last update: March 05, 2012 13:36:41
Thanks Dr.Xi, I was having a tough time changing the deployment context path of my web-app using the so-called context.xml file under /META-INF, it dint work (tomcat documentation at http://tomcat.apache.org/tomcat-6.0-doc/config/context.html , seemed pretty sure it would :() But I have one question, as changing server.xml is too instrusive for every web-app you build, is there any other way of pushing this configuration to one of the application specific files ? thanks, Venky
Created by Fang on November 08, 2011 20:55:00    Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print <p>john</p> <p>steve</p> <p>mike</p> with custom tag <my:foreach> : <my:foreach var="who" value="john steve mike"> ... These are the files: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/com/example/UIForeash.java : package com.example; import java.io.IOExcep... src/main/resources/META-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <faces-c... src/main/resources/META-INF/foreach.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by Fang on November 03, 2011 19:47:38    Last update: November 08, 2011 20:24:47
This is a step-by-step example to create a really simple facelet taglib (in JSF 2 with Maven). Create a simple Maven project with: mvn archetype:create -DgroupId=com.example -Dartif... Three files are created as a result: pom.xml src/main/java/com/example/App.java src/test/java/com/example/AppTest.java This project should be able to build with: mvn package Add facelet API dependencies to pom.xml : <project xmlns="http://maven.apache.org/POM/4.... The compiler plugin section is optional. Remove src/main/java/com/example/App.java , create a new Java class as the facelet Tag Handler ( HelloTagHandler.java ): package com.example; import java.io.IOExcep... This tag handler simply prints a "Hello" message. Create facelet tag declaration file src/main/resources/META-INF/hello.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... Build the JAR with mvn clean package Optionally, install it to the local repository: mvn install To use the taglib, simply drop the...
Created by Fang on October 28, 2011 13:49:40    Last update: October 30, 2011 19:23:25
This is a simple example to demonstrate the templating power of JSF facelets. If you've used struts tiles before, you'll recognize the simplicity of templating with facelets. I've stripped out everything else except the pages themselves, just to put our focus on facelets. This is a Maven based project, and you need Tomcat (or any servlet container) to run the resulting webapp. To begin with this is the list of files: ./pom.xml ./src/main/webapp/home.xhtml ./src... I left faces-config.xml in there for completeness sake, it may not be needed. The Maven POM ( pom.xml ): <?xml version="1.0" encoding="UTF-8"?> <project... Web app configuration ( WEB-INF/web.xml ): <?xml version="1.0" encoding="UTF-8"?> <web-app... Empty WEB-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <!-- Thi... index.jsp is simply a redirect to home.jsf : <% response.sendRedirect("home.jsf"); %>...
Created by Dr. Xi on April 27, 2011 11:57:36    Last update: April 27, 2011 11:58:35
This is a sample struts-config.xml file for Struts 1.x . <?xml version="1.0" encoding="UTF-8"?> <!DO...
Created by Dr. Xi on April 26, 2011 21:25:55    Last update: April 27, 2011 11:08:57
The following code validates a web.xml file against the web-app 2.5 schema: // Java XML validation with schema import java.... web.xml used for testing: <?xml version="1.0" encoding="UTF-8"?> <web-ap... According to Java API doc , validation can also be done while parsing by calling setSchema on the parsing factory. However, validation doesn't work for the SAXParserFactory! // Java XML validation with schema import java....
Created by Dr. Xi on November 23, 2010 20:20:01    Last update: March 01, 2011 13:38:51
I tried to find a GZIP compression servlet filter to compress a large log file that we send down to the browser. Most of the implementations I found were overly complicated and many buggy. This is a simple implementation that worked for me. The filter: package filter.demo; import java.io.*; i... Config web.xml : <filter> <filter-name>gzipFilter</filte... The ugly anonymous inner class could have been avoided if the servlet API did not insist on ServletResponse.getOutputStream returning the bogus ServletOutputStream class (instead of the plain OutputStream ). Additional Note: In an earlier version of this filter, the gzip headers were added in doFilter , like this: // This is NOT good! if (supportsGzip) { ... It turned out that the ServletResponse methods sendError bypasses the gzip...
Created by Dr. Xi on February 10, 2010 23:39:37    Last update: 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-ap...
Created by Dr. Xi on January 08, 2010 03:53:37    Last update: January 08, 2010 03:54:56
This is an Ant custom task to merge Properties files I lifted from http://marc.info/?l=ant-user&m=106442688632164&w=2 , with some minor bug fixes. Example usage: <taskdef name="mergeProperty" classname="ant.task.... Implementation: package ant.task.addon; import java.io.Buff...
Created by Dr. Xi on September 05, 2008 21:37:35    Last update: September 05, 2008 21:43:13
The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory. For example, DirectoryIndex index.html index.txt /cgi-bin/index... will cause Apache to look for index.html and index.txt in the requested directory in turn, and run /cgi-bin/index.pl if neither is found. DirectoryIndex overrides the Indexes option and can be used in server config , virtual host and directory sections, or in the .htaccess file. The Indexes option allows Apache to return a directory listing when a directory is requested: <Directory /web/docs> Options Indexes FollowSym...