Archive for Java Appication

Spring Internationalization Setting

  1. in
  2. in /WEB-INF/web.xml:
     <bean id="secureHandlerMapping" 
        <property name="interceptors">
            <ref bean="loginInterceptor"/>
            <ref bean="localeChangeInterceptor" />
  3. In /WEB-INF/spring/spring-servlet.xml
     <bean id="messageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8"/>
      <bean id="localeResolver">
          <property name="defaultLocale" value="en"/>
      <bean id="localeChangeInterceptor">
          <property name="paramName" value="lang" />
  4. In jsp file
    <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
  5. Language links in jsp file:
    <li><a href=”?lang=cn”><spring:message code=”index.chinese”/></a></li>
    <li><a href=”?lang=en”>English</a></li>
  6. In class folder:
  7. In
    index.schoolName=School Name
  8. In
  9. Create utf-8 code in
  • copy to
  • translate in
  • use tool native2ascii.exe
    C:\……\jdk\bin\native2ascii.exe    -encoding utf8        C:\fromFolder\  C:\toFolder\


Leave a Comment

How to disable browser back after logout

For jsp, put the following code on every page:

response.setHeader(“Cache-Control”,”no-cache”); //HTTP 1.1
response.setHeader(“Cache-Control”,”no-store”); //HTTP 1.1
response.setHeader(“Pragma”,”no-cache”); //HTTP 1.0
response.setDateHeader (“Expires”, 0); //prevents caching at the proxy server

Leave a Comment

Basic Spring Project Setup Template



  • user signup/login/edit module
  • session management module
  • security interceptor module
  • global code list
  • user management module including user list, delete,active/inactive…
  • code type/code management module including list, delete, reorder…

How to use it

assume local folder is “c:\WYX\tmp”

  1. Extract zip file to your local “c:\WYX\tmp” and change the folder name from “yaan” to “myfirstproject”.
  2. New project in IDE, e.g. IntelliJ IDEA:
    project name:      “myfirstproject”,
    project location: c:\WYX\tmp\myfirstproject,
    Create module:    checked
    module name:     java
    module content root:   c:\WYX\tmp\myfirstproject\src\java
    module filelocation:     c:\WYX\tmp\myfirstproject\
  3. new module
    module name:     web
    module content root:   c:\WYX\tmp\myfirstproject\src\web
    module filelocation: c:\WYX\tmp\myfirstproject\
    next:   Do not create source directory
  4. In “Project Structure”, create “myfirstproject_lib” from lib folder
  5. Global replace “greenbestow” to “myfirstproject”, “GreenBestow” to “Myfirstproject”
  6. Change package name “greenBestow” to “myfirstproject”
  7. Change
  8. In build.xml cahnge home, libhome, war_file
  9. Change greenBestow-servlet.xml to myfirstproject-servlet.xml
  10. change
    public class BaseJdbcService extends NamedParameterJdbcDaoSupport {
  11. for insert query, using:
    SqlParameterSource fileParameters = new BeanPropertySqlParameterSource(tag);
    KeyHolder keyHolder = new GeneratedKeyHolder();
    int row = getNamedParameterJdbcTemplate().update(q, fileParameters, keyHolder);
    if (row>0) {
  12. add the following into web.xml
    <param-value>[what you have in display-name or something unique to your web app]</param-value>


Leave a Comment

Remote debug setting

set JAVA_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n

in IntelliJ IDEA:

  1. add new Configurations – Remote
  2. change the port to 8001

Leave a Comment

SEVERE: Error listenerStart

When you start tomcat server and get the error “SEVER: Error listenerStart”… “SEVERE: Context [/xxxxxxxxxx] startup failed due to previous errors”, it is because you have multiple apps under webapp/ folder. You need add the following lines in every app’s web.xml


It is Log4jWebConfigurer’s requirement…

Leave a Comment

How to call a javascript function in the iframe?


Leave a Comment

Page not found error in a jsp

1) Put the following code in web.xml:


2) Create above jsp files. Usually to be safe you should make error pages that are larger then 512 bytes. The threshold varies per HTTP status code. You can look at what your thresholds are currently set to. In IE 5 and greater the settings are stored in the registry under[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\ErrorThresholds]

Err Size(bytes)
400 512
403 256
404 512
405 256
406 512
408 512
409 512
410 256
500 512
501 512
505 512

Leave a Comment

Older Posts »