Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Monday, December 27, 2010

How to change Tomcat default character encoding

We faced an issue last week on linux machine,

In a tomcat deployed server, The non-english characters getting from web services are not displaying correctly.

We write a main program in java and retrieved the data through web-service. its parsed well and correctly displayed the non-english character.

So the issue is with tomcat, after investigation we found this.


In the catalina.bat (catalina.sh) add the java args...

set JAVA_OPTS=-Djavax.servlet.request.encoding=UTF-8 -Dfile.encoding=UTF-8

then all encodings seem to come across as UTF-8 by default.. 
This resolved the problem.

source: http://marc.info/?l=tomcat-user&m=108576957301771&w=3

----------------------
+20110113
Added some more info:

Configuring Tomcat's URI encoding

By default, Tomcat uses ISO-8859-1 character encoding when decoding URLs received from a browser. This can cause problems when Confluence's encoding is UTF-8, and you are using international characters in attachment or page names.
  1. Edit conf/server.xml and find the line where the Coyote HTTP Connector is defined. It will look something like this, possibly with more parameters:
    <Connector port="8080"/>
  2. Add a URIEncoding="UTF-8" property to the connector:
    <Connector port="8080" URIEncoding="UTF-8"/>
  3. Restart Tomcat
-------------------
Also check this

Monday, November 30, 2009

java.lang.OutOfMemoryError: PermGen space on java Tomcat server, linux


I got this error last day when try to open an jsp page,

server is Tomcat5.5 and os is linux

I found this link http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ it was very helpful to fix the issue

1. I just added the following code to my catalina.sh file

JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"


2.
You can create jsp page with the following code to evalute your memory details


# <%@ page import="java.lang.management.*, java.util.*" %><%

# response.setContentType("text/html");

# Iterator iter = ManagementFactory.getMemoryPoolMXBeans().iterator();

# while(iter.hasNext()){

# MemoryPoolMXBean item = (MemoryPoolMXBean) iter.next();

# MemoryUsage mu = item.getUsage();

# long used = mu.getUsed();

# long committed = mu.getCommitted();

# long max = mu.getMax();

# %>

# MEMORY TYPE: <%=item.getName()%>

# Used: <%=used%>

# Committed: <%= committed%>

# Max: <%=max%>

# <%}%>



The output look like

localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 25 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 64 mb
------------------------------------


After add this code JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=256m"
I got PS Perm Gen size as

MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 256 mb