Saturday, May 22, 2010

use OnClick with caution

JSP Code :

<a href="abc.jsp" onclick='<% session.invalidate(); %>'>LOGOUT</a>

The above statement gets converted to Servlet CODE :
out.write("<a href=\"abc.jsp\" onclick='");


What ever scriplet you write in onclick, will get executed every time the JSP is called. Not only on onclick as can be wrongly assumed.

Thursday, May 20, 2010

BUG in struts2

Actually I used

Now, I have specified type as button, so I expected that it will not go to action on click on the button.

But what happens is

when I click on button, it asks if I want to close the window,
Now, even I click NO, it still goes to action specified in form.

Solution : This is a BUG in struts2.

the HTML tag that is generated is something like:

<button type="submit" id="test_0" value="Submit" class="button positive save">Submit</button>

Please note that we have given type=button in s:submit tag, and the HTML generated still contains type=submit.

Can get some information from

Sunday, May 16, 2010

Internationalization tips for JSP

In order to display the complex script characters like Japanese, Chinese, etc in the browser window, the following changes need to be made at the beginning of each JSP file:

<%@ page language="java" 
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Wherever input controls are present, the following additional steps need to be taken:
Add the following code before reading any parameters in the previous JSP file:

request.setCharacterEncoding("UTF-8"); // Set the request encoding

While sending output to a browser:

response.setContentType ("charset=UTF-8");