ITeye博客

GAE上使用Struts2

acheron · 2009-05-26 17:13 · Struts · Markdown

Google App Engine for Java

这里看GAE支持的java框架/技术/语言 列表

http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine

 

然后是让Struts2运行在gae上的方法

这里有2个相关资料

 http://groups.google.com/group/google-appengine-java/browse_thread/thread/19018b0317f27817/ec19c458bb15413b?lnk=gst&q=struts2#ec19c458bb15413b

 

http://www.nabble.com/Google-App-Engine-support--td22972179.html

 

只看下文也可以

使用Struts2时候报异常

WARNING: Caught OgnlException while setting property 'location' on type
'org.apache.struts2.dispatcher.ServletDispatcherResult'.
java.lang.IllegalAccessException: Method [public void
org.apache.struts2.dispatcher.StrutsResultSupport.setLocation(java.lang.Str­ing)]
cannot be accessed.
   at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:508)
   at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:812)

 

SEVERE: ParametersInterceptor - [setParameters]: Unexpected Exception
caught setting 'name' on 'class com.ociweb.gaestruts2.HelloAction: Error
setting expression 'name' with value '[Ljava.lang.String;@24de7d'

 

解决方法:

1. 建class如下

package com.jun.util.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;

/**
 * 为了让Struts2能在AppEngine上运行,因此要在web.xml中添加这个监听 **
 */
public class InitListener implements ServletContextListener,
		HttpSessionListener, HttpSessionAttributeListener {

	public InitListener() {
	}

	public void contextInitialized(ServletContextEvent sce) {
		OgnlRuntime.setSecurityManager(null);
	}

	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
	}

	public void sessionCreated(HttpSessionEvent arg0) {
		// TODO Auto-generated method stub
	}

	public void sessionDestroyed(HttpSessionEvent arg0) {
		// TODO Auto-generated method stub
	}

	public void attributeAdded(HttpSessionBindingEvent arg0) {
		// TODO Auto-generated method stub
	}

	public void attributeRemoved(HttpSessionBindingEvent arg0) {
		// TODO Auto-generated method stub
	}

	public void attributeReplaced(HttpSessionBindingEvent arg0) {
		// TODO Auto-generated method stub
	}

}

 

 

2.web.xm配置监听器

<listener>
         <listener-class>com.jun.util.listener.InitListener</listener-class> 
</listener> 

 

此时再运行你的struts2项目就行了

评论(4)

  1. #4 楼 · lattimore · 2011-10-23 23:21

    swanky_yao writes:

    [quote=wukaiwhu]楼主你好,我也在尝试把struts2加到gae里去,程序在本地gae环境下运行正常.就是上传时新添加的那些jar包都不会上传,不知道这是为什么,你有碰到这种情款么? 我的struts2相关jar库文件都已经放在了WEB-INF/lib里.[/quote]

    你把他copy到WEB-INF/lib里,但是你还得在MyEclipse里把这些lib添加到项目里才行啊。在java build libs里添加jars

    你似乎还没有回答到点子上!

  2. #3 楼 · swanky_yao · 2010-03-25 11:19

    wukaiwhu writes:

    楼主你好,我也在尝试把struts2加到gae里去,程序在本地gae环境下运行正常.就是上传时新添加的那些jar包都不会上传,不知道这是为什么,你有碰到这种情款么? 我的struts2相关jar库文件都已经放在了WEB-INF/lib里.

    你把他copy到WEB-INF/lib里,但是你还得在MyEclipse里把这些lib添加到项目里才行啊。在java build libs里添加jars

  3. #2 楼 · fkpwolf · 2009-11-18 10:45

    http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine?pli=1 这个链接很好,顶LZ

  4. #1 楼 · wukaiwhu · 2009-07-24 14:13

    楼主你好,我也在尝试把struts2加到gae里去,程序在本地gae环境下运行正常.就是上传时新添加的那些jar包都不会上传,不知道这是为什么,你有碰到这种情款么? 我的struts2相关jar库文件都已经放在了WEB-INF/lib里.

评论功能维护中,当前仅展示历史评论。