Cool open source html templates

by lichen 7/10/2007 10:08:00 AM

http://www.opensourcetemplates.org/ has some really nice templates.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

Add Struts to regular Websphere 6.0 dynamic web applications

by lichen 7/9/2007 11:23:00 AM
  1. Add jar files to WEB-INF/lib
    • commons-beanutils.jar
    • commons-collections.jar
    • commons-digester.jar
    • commons-fileupload.jar
    • commons-lang.jar
    • commons-logging.jar
    • commons-validator.jar
    • jakarta-oro.jar
    • struts.jar
  2. Add tld files to WEB-INF
    • struts-bean.tld
    • structs-html.tld
    • structs-logic.tld
    • structs-nested.tld
    • structs-template.tld
    • structs-tiles.tld
  3. Add XML files
    • structs-config.xml
    • validation.xml
    • validator-rules.xml
  4. Add the following to web.xml:

<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>

<init-param>

<param-name>debug</param-name>

<param-value>5</param-value>

</init-param>

<init-param>

<param-name>detail</param-name>

<param-value>2</param-value>

</init-param>

<init-param>

<param-name>validate</param-name>

<param-value>true</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<jsp-config>

<taglib>

<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-html.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-template.tld</taglib-location>

</taglib>

<taglib>

<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>

<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>

</taglib>

</jsp-config>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Java

J2SE and J2EE version in WebSphere 6.0

by lichen 7/9/2007 11:04:00 AM
  • J2SE 1.4
  • J2EE 1.4
    • Servlet 2.4
    • JSP 2.0
    • JSTL 1.1
    • JSF 1.1
    • Struts 1.1

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Java

Frustration with JSP technology

by lichen 7/7/2007 4:17:00 PM

The problem

When I worked at ESRI, I worked on the .net version of ArcGIS Server Manager, which is a web-based front-end for ESRI’s ArcGIS Server products. The Java team also has a Java version of the product based on the same UI spec. I was the only .net developer on the .net version while the Java team had 2 ½ developers on the Java version, but I was constantly ahead in features. I was proudly thinking that I am a much better developer than my peers on the Java team.

However, a recent project changed my thinking. My current employer is migrating some VB6 based projects to Java. I developed a web service in Java. At the end of project, I have some time left. So I decide to develop a few simple CRUD pages for the configuration table. The idea is fairly simple: I want to develop a page that lists the records in the table. It has a single form at the end of the page that allows me to insert a new record, as seen in the picture below:

Normal Mode

When I try to edit the record, the page will enter the edit mode. The row that I try to edit would contain some textboxes. The edit/delete link would change to update and cancel. The insert form would be hiden, as seen in the picture below:

 

Normal Mode

This is a fairly standard feature in asp.net. I can develop a page like this in a few clicks in less than an hour. However, in Java/JSP, I search the Google with words like “Java and RAD” but could not find any rapid application development solution that is simple to use.

The solution

I did a survey on how Java developers do similar things with JSP. JSP allows scriptlets, like ASP developers embed script inside the ASP page. However, it is not good practice to embed lots of code in the contents page. Servlet is a good place for code. You cannot embed Servlet in an JSP page. A typical pattern is that people will have a page post to a Servlet (controller) to do all the processing. The servlet will then forward/redirect to a JSP page (View) to display the result. That is a good practice except the view could need lots of scriptlets if there are lots of conditional rendering. It is possible to embed Java Bean in JSP. However, Java Bean does not have access to Http context. To gain access to the Http context, one would have to develop custom Jsp tags.

Since my goal is to develop a CRUD page that allows me to edit an simple table, here is the design approach that I take. I have one JSP page and 3 servlets. The 3 servlets are used for handling insert, delete and update. The JSP is reponsible for displaying the data. It also contains scriplets to switch between normal and edit mode:

  1. Normal mode: Display the table normally. Show the insert form.
  2. Edit mode: Display the row being edited as textboxes. Display the button of the row as Update and Cancel. Hide the insert form.

Here is the code:

boolean editMode = (request.getParameter("kc") != null);

if (editMode) {

    action = "updateConfig?kc=" + request.getParameter("kc") + "&kk=" + request.getParameter("kk");

} else {

    action = "addConfig";

}

<form action="<%= action %>" method="post">

    <table>

        <tr>

            <th>Configurationth>

            <th>Keyth>

            <th>Valueth>

            <th>th>

        tr>

<%

while(rs.next()) {

%>

<% if (editMode && rs.getString("CONFIG_NAME").equals(request.getParameter("kc")) && rs.getString("KEY").equals(request.getParameter("kk"))) {%>

        <tr>

            <td><%= rs.getString("CONFIG_NAME") %>td>

            <td><INPUT type="text" name="key" size="20" maxlength="64" value='<%= rs.getString("KEY") %>'>td>

            <td><INPUT type="text" name="value" size="20" maxlength="254" value='<%= rs.getString("VALUE") %>'>td>

            <td><INPUT type="submit" value="update"><a href='config.jsp'>cancela>td>

        tr>

<% } else { %>

        <tr>

             <td><%= rs.getString("CONFIG_NAME") %>td>

             <td><%= rs.getString("KEY") %>td>

             <td><%= rs.getString("VALUE") %>td>

             <td>

                 <a href='config.jsp?kc=<%= rs.getString("CONFIG_NAME") %>&kk=<%= rs.getString("KEY") %>'>edita>

                 <a href='deleteConfig?kc=<%= rs.getString("CONFIG_NAME") %>&kk=<%= rs.getString("KEY") %>'>deletea>

             td>

         tr>

<% }

}

%>

<% if (!editMode) {%>

         <tr>

             <td><INPUT type="text" name="configName" size="20" maxlength="64">td>

             <td><INPUT type="text" name="key" size="20" maxlength="64">td>

             <td><INPUT type="text" name="value" size="20" maxlength="254">td>

             <td><INPUT type="submit" value="insert">td>

          tr>

<% } %>

      table>

form>

I felt that I go back 10 years in time and become an asp programmer again. So here is what I think why at ESRI my peers on the Java team are so much slower than me:

  1. JSP does not have an efficient method like code-behind in asp.net that allows close interaction between code and view.
  2. The MVC frameworks like Struts that is main stream in Java community tend to product large number of classes for simply thing. Also the MVC promotes separation of responsibility and reuse at the first glance. However, in real life, only a small number of classes are actually reused; most of classes are only used once. The large number of classes create problems in both naming and finding things. In ASP.NET, it is far more easier to work with things and find code.
  3. JSP lacks a component model to work with non-HTML controls. Here the non-HTML control means a sophiscated control like Tree that is composed of html, images, css. Its behavior is manipulated by Javascript and DHTML and states often saved in a hidden control. JSP and MVC framework like Struts can only handle native HTML controls. The rich components are handled outside of framework. Therefore, I would say that JSP is about half way between asp and asp.net. For an asp.net developer to work on JSP, it is like going back to stone page.
  4. I hope JSF will provide a rich component model that rivals that of ASP.NET. Unfortunately, both the development and the adoption have been so slow. It does not help that our company is still standardized on J2EE 1.4.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | ASP.NET | Java

AntispamValidator Control

by lichen 7/7/2007 3:43:00 PM
I have just released the AntispamValidator control.  AntispamValidator control is an asp.net validation control that can be used to prevent posting of contents that contain lots of links. Spammers like to post contents with lots of links to increase the Google ranking of their sites. The control can be downloaded from http://www.dotneteer.com/downloads/AntispamValidator.zip. You might also visit http://www.dotneteer.com/projects/AntispamValidator.aspx and post a content with lots of links to see if in action.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | ASP.NET

Stop the blog spam

by lichen 7/7/2007 11:53:00 AM

I have a medium-low traffic blog, but it often becomes the victim of blog spam. In the past, I turned off the blog ping-back to stop the automatic spam first. Then I added Miguel Jimenez's free Clearscreen SharpHIP CAPTCHA control that I saw in use on Scott On Writing. I use the same .text blog engine as Scott Mitchell so I often visit his site when I encounter problems.

The CAPTCHA control stopped all the automatic spam but it did not stop the manual spam. Spammers can hire cheap labor from third-world county to spam manually. I still got in average 3 spams each day. It still becomes a hassle to delete them if I do not clean them up for a while. Scott simply turned off the comment support when he is going away. I decide to write a validator control to stop the spam.

The idea is to stop the spam at its cause. The economic reason behind the blog spam is to generate links to other sites so that Google will rank those sites higher. So a blog spam always contain a large number of links. Since a normal blog comment seldom needs more than a few links, a way to stop the spam is to detect the number of links in a comment. If the number of links is beyond a threshold, the validator control will stop them. I spent a few hours to implement the control. I have not seen a single spam since them. For now, the spammer are looking for easier targets.

I will publish my control in near future to be used by the community.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | ASP.NET

Connection pooling when access DB2 via ADO

by lichen 6/28/2007 12:24:00 PM
I did some research. We currently use DB2 ODBC Provider through ADO (which in turn uses ODBC Provider for OLEDB – MSDASQL). Both ODBC and OLEDB have roles in connection pooling.

By default, DB2 ODBC connection pooling is on with timeout = 60 sec. That is, a connection will be removed from the pool if the connection is not used for 60 sec. There is no max/min bound for ODBC connection pool; it is unbounded. OLEDB resource pooling for MSDASQL is also on. That means that connection could be pooled on both at OLEDB level and at ODBC level. The behavior of OLEDB resource pool is different to ODBC. It does not have max/min bound either. However, OLEDB will drop the entire pool when there are no active connections. In order to keep the pool, Microsoft suggests having code to keep one connection open (see http://msdn2.microsoft.com/en-us/library/ms810829.aspx).

IBM suggests that we disable OLEDB resource pooling for MSDASQL (see http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/c0010958.htm) so that it does not interfere with ODBC resource pooling. By default, both OLEDB resource pooling and ODBC connection pooling on.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL

Notes on WebSphere Web Project Deployment, Part 3 - Deployment through Admin Console

by lichen 6/15/2007 12:58:00 PM

The following steps are only required for the first time deployment to the server:

 

  1. Configure Environment Variables for DB2 Universal JDBC Drivers. From Admin Console, client Environment/WebSphere Variables. Make sure that the correct node is selected. Configure the following environment variables:

DB2UNIVERSAL_JDBC_DRIVER_PATH

UNIVERSAL_JDBC_DRIVER_PATH

  1. Configure JDBC Providers: Click Resources/JDBC Providers. Make sure that the correct node is selected. If DB2 Universal JDBC Driver Provider is not already created, click New. From database type, select DB2. From provider type, select DB2 Universal JDBC Driver Provider. From implementation type, select “Connection Pool Datasource”. Click Next. Accept the default for Class Path and Native Library path. If the class name is not populated, enter “com.ibm.db2.jcc.DB2ConnectionPoolDataSource”.
  2. Create J2C Authentication data: Click Security/Global security. Expand JAAS Configuration under Authentication on the right-hand-side. Click J2C Authentication data. Click new to create a new entry and set the follow parameters:

Alias:

Description:

User ID:

Password :

  1. Create Data sources: From DB2 Universal JDBC Driver Provider screen, click “Data sources” under “Additional Properties”. Click New to create a new Datasource:

Name:

JNDI Name:

Component-managed authentication alias:

Fill the DB2 Universal data source properties with the information from prerequisite 3. Accept default for the rest of parameters.

Save the configuration. Click test connection to ensure that the DB2 connection is successful.

  1. Deploy the enterprise application: Click Applications/Enterprise Applications. Click Install. Browse to the ear file and leave context root empty. Click Next. On override, select “Do not override existing bindings”. On Virtual Host, select “Use default virtual host name for web modules”. Enter the host name from prerequisite 1. Click Next. From installation options, do not pre-compile JSP. Select Distribute Application. Accept the default for the rest and click Next.
  2. Map resource reference to Resources: The web service contains resource reference jdbc/Q2WSDatasourceReference. Clip MapResource reference to resources. Select the module, select the resource JNDI name from step 4, select user default method and select alias in step 2 in the authentication data entry.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Java

Notes on WebSphere Web Project Deployment, Part 2 - Resource Reference

by lichen 6/15/2007 12:25:00 PM

My web project connects to a database. WebSphere server can provide pooled connection as datasource. In my application, I just simply get the connection by lookup through the context:

   InitialContext ctx = new InitialContext();
   DataSource ds = (DataSource)ctx.lookup(dataSourceUri);
   con = ds.getConnection();

Using this way, I can let container manages the connection and security. I just simply retrieve the connection from my code. Direct resource lookup is deprecated in WebSphere 6 for security reasons. Now we have to look up the datasource through resouce reference (i.e., indirect lookup). Application will specify the resource reference that the application will lookup in the deployment descriptor. The container can link the resource reference to resource by confiugration. This way, a data source is not exposed to any application.

We have to let application tell which resource reference it is going to lookup first. To do this, cllick the Deployment Descriptor in the web project and click the References tab. Add a new resource reference. For data resources, set type to javax.sql.DataSource. Set authentication to container. To make it easier to work with local testing environment, we can set the JNDI name tha the resource reference should bind to under WebSphere Bidings. Set JNDI Login Configuration to None.

In the next part, we will specify how to configure the resouce reference in the admin console.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Java

Notes on WebSphere Web Project Deployment, Part 1 - Utility Jars and Projec Utility Jars

by lichen 6/15/2007 11:43:00 AM

I created a dynamdic web project using Rational Application Developer (RAD) 6.0. The wizard automatically created an EAR project. The EAR project is for creating the Enterprise Archieve (EAR file). I can right click on my EAR project and select export. I can then deploy the single EAR file to my WebSphere server.

The web project uses some third party jar files such as log4j. These utility jars must be deployed with the web application. So I dropped those jar files in my EAR project. From the web project, I right clicked on the web project, select properties.../ Then I select Java Build Path, click on the Libraries tab and then click “Add JARs...”. I can then select any JAR file that is in my workspace. The project file will use relative path to reference the Jar file so that the workspace is portable from one developer to another.

I have some Java code that can be reused in other projects so that I do not want to place them in my web project. I create seperate projects for the code. The projects need to be compiled into Jar files and then packaged into my EAR file. With RAD, there is an easy way to do it. Just click on the Deployment Descriptor of my EAR project, clicke on the Module tab, under Project Utility JARs, click Add to add all my library projects. When I export my EAR file, RAD will automatically create JAR files from my projects and include them in the EAR file.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Java

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Pages

    Recent comments

    Authors

    Tags

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2010

      Sign in