My mistakes

Archive for the ‘Java’ Category

SEVERE: Servlet.service() for servlet EmailServlet threw exception
java.lang.SecurityException: Access to default session denied

Please try the below solutions
1) Verify there is no duplication of javamail.jar in the tomcat or in your application.

Check the tomcat_home/lib , your_app/WEB-INF/lib

2)  Verify you are using only one email configuration to call the Session.getDefaultInstance through out the site.

Because as per the http://docs.oracle.com/javaee/6/api/javax/mail/Session.html#getInstance%28java.util.Properties documentation the replication of the configuration with getDefaultInstance will cause an error.

In such case if you want to insist with the new configuration then use Session.getInstance instead of Session.getDefaultInstance.

Tags:

Things to take care

1) Set the contentType on the jsp via

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

2) Set this tag inside the jsp:
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />

3) Add the below filter to the web.xml

<!– Ensure UTF-8 encoded pages so that certain characters are displayed and submitted correctly –>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

4) Make sure the database fields have appropriate collation like utf-8, utf-16

Tags: