Struts 2 on GAE – Error: result ‘null’ not found

Problem

Developing Struts2 on Google App Engine, in following environment.

  1. Struts 2.3.1.2
  2. JDK 1.6
  3. Eclipse 3.7 + Google Plugin for Eclipse
  4. Google App Engine Java SDK 1.6.3.1

Just started a simple Struts2 hello world example, when access the action class, hit error “Error: result ‘null’ not found”, in both local development and real production GAE environment.

struts2 on gae - result null error struts2 on gae - result null error

Solution

OGNL is performing some security checking, which is not support in GAE. To make Struts 2 works on GAE environment, you need to create a listener in web.xml and set the OGNL security manager to null.

OgnlRuntime.setSecurityManager(null);

Full example.

package com.mkyong.listener;
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
 
import ognl.OgnlRuntime;
 
public class Struts2ListenerOnGAE implements ServletContextListener,
HttpSessionListener, HttpSessionAttributeListener {
 
public void contextInitialized(ServletContextEvent sce) {
OgnlRuntime.setSecurityManager(null);
}
 
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
 
}
 
@Override
public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
 
}
 
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
 
}
 
@Override
public void attributeAdded(HttpSessionBindingEvent arg0) {
// TODO Auto-generated method stub
 
}
 
@Override
public void attributeRemoved(HttpSessionBindingEvent arg0) {
// TODO Auto-generated method stub
 
}
 
@Override
public void attributeReplaced(HttpSessionBindingEvent arg0) {
// TODO Auto-generated method stub
 
}
 
}

File : web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

 
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
 
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
 
<listener>
<listener-class>com.mkyong.listener.Struts2ListenerOnGAE</listener-class>
</listener>
 
</web-app>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s