All 26 entries tagged Java

View all 241 entries tagged Java on Warwick Blogs | View entries tagged Java at Technorati | There are no images tagged Java on this blog

October 25, 2006


<c:forEach begin="0" end="${numbers}"   var="status">
<c:if test="${status %2 == 0}">hi</c:if>

The value of varStatus represents the name of a scoped variable that you can use to obstain information about the status of the iteration performed by action.

The following code

<c:forEach begin="0" end="${pageNumbers}"   var="i" varStatus="status">
var: ${i} and status: ${status.count} <br/>

generates the following output:

var: 0 and status: 1
var: 1 and status: 2
var: 2 and status: 3
var: 3 and status: 4 
<c:if test='$( param.cardType =="Visa"}'></c:if>
<c:if test='$( not empty param.cardType}'></c:if>
<c:if test='$( isRight}'></c:if>
 <c:when test='${isRight}'>

October 11, 2006

Starting sequence of Spring Web App

The sequence is :
Listener, filter, frameWorkServlet


Standard container startup
configuring application event listeners
sending application start event
contextLoaderListener -> contextLoader -> WebApplicationContext

Starting filters
start FrameworkServlet
Load webApplicationContextfor FrameworkServlet
Pre-instantiating singletons in factory

September 27, 2006

Textile Latex

September 20, 2006

Special characters in URL and Servlet output

Users send a URL whose parameter value containing special characters (e.g. £) to a Servlet.
A Servlet then extract the parameter value containing special character. Use it as an key to retrieve values from properties.
The retrieved values also contains special character.
Then Servlet output the values to client, who will render them as options in a dropdown list.

1. £ is encoded by the browser before sending to server. Server will get encoded value and cannot use this as a key to get the values.

I borrowed a piece of javascript from a colleague and did a little modification.

    //manually encode
     var size = value.length; 
     for(var i=0; i<size; i++) { 
         var c = value.charCodeAt(i) .toString(); 
          output += '%26%23' + c ;      

On the server side,the Servlet will decode the value:

              String[] strings = receivedString.split("&#");
        char[] chars=new char[strings.length];
        int index =0;
        for (int i = 0; i < strings.length; i++) {              
           chars[index++]=(char) Integer.parseInt(strings[i]);
        String decodedString = new String(chars,0, index);

It then got the value correctly.

Further problem
The code: response.getWriter().write(sb) where sb will contains special character like £, get display incorrectly. Seems the browser does not understand the £.

Eventually I set response.setContentType(“text/html”) and it works. I initially thought the default value of content type is “text/html” but apparent it’s not.

Javascript: String.charCodeAt: return unicode values range from 0 to 65,535. The first 128 Unicode values are a direct match of the ASCII character set.
Java: char: The char data type is a single 16-bit Unicode character. It has a minimum value of ’\u0000’ (or 0) and a maximum value of ’\uffff’ (or 65,535 inclusive).

that’s why the “%26%23” in javascript can be interpreted as ” ampersand hash ” in Java

June 20, 2006

Singleton in Spring

Today I found an error in my project related to the singleton in Spring.

A class Pager is a Spring bean injected to a controller by IoC container.
In one method of the controller, it use variable to store submissions from a form.

If two threads send the request at the same time, then was written twice. So potentially the controller will return wrong result for one form.

April 26, 2006

When Oracle meet Java

With the popularity of n-tier web applications and Java language, Oracle DBA inevitably has to deal with Java applications. DBA can work more efficiently if they know Java.
1) DBA can help Java applications to run faster. There are some special considerations for managing Oracle as the backend of n-tier application. This presentation will discuss the impact of following elements: Java app server, Object-relational mapping (ORM) tools , common mistakes of Java developers and some cool Oracle features to speed up Java applications.
2) Java can help DBA to managing Oracle efficiently. This presentation will discuss the advantage of Java over shell scripts, the power of JDBC. DBA can use JDBC to centrally manage multiple databases and monitor various database services.


With the popularity of n-tier web applications and Java language, Oracle DBA inevitably has to deal with Java applications. DBA can work more efficiently if they know Java.

DBA can help Java applications to run faster

  • With a Java application server in front of Oracle, you do not need to use shared server. Java connection pool is equivalent to Oracle dispatcher.
  • Heavy cache in App server. Less hit on DB
  • Java developers fancy Object-relational mapping (ORM) tools. They abuse table joins and let tools generate complicated queries to torture Oracle
  • Work with Java developers and share knowledge. Educate Java developers to write high-performance query
  • Be sensitive to new features, e.g., asynchronous commit can speed up Java batch commit

Java can help DBA

  • Java applications can send email and SMS to give DBA timing alert
  • JDBC is becoming more and more powerful. Oracle SQL Developer is based solely on JDBC, no Oracle client installation required.
  • Using JDBC connection to detect the availability of database. It can provide useful information like ‘network adaptor exception’, ’db not available’, ‘maximum connection exceeded’.
  • Use one application to centrally manage multiple databases.
  • Can monitor multiple functions: the status of database, standby logical apply service status, audit log.

March 31, 2006

java.sql.Date and java.sql.TimeStamp

I forget the followings:

java.sql.Date only display the date info, the time part is rounded to 00:00:00. If you want to display time , using TimeStamp.

February 07, 2006

Tags : jsp component

Create tag file:

Can use other tag libraries:

[%@ taglib prefix="c" uri="" %]
[%@ attribute name="label" type="java.lang.String" required="true" %]
[%@ attribute name="compulsory" type="java.lang.Boolean" required="true" %]



[c:when test="${compulsory}">${label}[span class="required_true"]*[/span][/c:when]



Import tag libraries:

<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

Use tag files:

[tags:inputTextField bindPath="" label="List label" compulsory="${true}"/]

January 27, 2006


5 out of 5 stars

Great Book.It bring me the whole world of refactoring.

Eclipse IDE makes refactoring job a joyable task. I can seriously say: it is fun.

September 27, 2005

JMock Test

Follow-up to Unit Test from Oracle/Java/Others

I don't like JMock before. When I did code refactoring, a lot of tests were broken through my refactoring are correct.

However, I find some very useful point of Jmock test: to mock some classes that are impossible to construct and some methods that are difficult to get around.

I have a upload file controller. In the first instance, it is impossible to construct a MultipartFile class. I used the following code to get around:

Mock fileMock = mock(MultipartFile.class);
MultipartFile multipartFileProxy = (MultipartFile) fileMock.proxy();
fileMock.expects(atLeastOnce()).method("getOriginalFilename").will(returnValue("a b.doc"));
long fileSize = 1;

Search this blog

Search Warwick Blogs



Most recent comments

  • Oracle 11g is the clear leader in this area. Oracle has invested heavily into self–tuning capabiliti… by shaane on this entry
  • All the features are very nice.I like Repair Advisors the most.Oracle 10G introduced some of the dat… by lucy on this entry
  • "logical standby failed to re–start, I am also getting the same error. I have search on internet and… by anemia on this entry
  • Thanks for the nice information because from last three days i am stuck on this problem…. by robot vacuum on this entry
  • So what happen City speed dating when you tried this coding once in your PC.. Please tell me so i am… by John Bergeron on this entry
RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder