struts2与gwt的整合

      最近一直在研究struts2与gwt的整合,进google的官方网找了很多资料也下载他们的dmeo,可惜一直没有成功,也有不少人发帖后来看了这2位高手的文章:

  下面是url:

   http://code.google.com/p/struts2gwtplugin/wiki/ZeroConfig

   http://code.google.com/p/struts2gwtplugin/wiki/Howtouse

   里面虽然写得有点模糊但是可以分析出一下要点:

   1,下载 struts2gwtplugin插件地址 http://code.google.com/p/struts2gwtplugin

   2,struts2相关的jar包 (关于struts2相关知识这里不提)

建立web项目这里要是以  Dynamic web project为准。

   关于gwt,与strust2细节部分不说了。我将项目上传即可,

这里具体说下gwt与struts2之间的细节问题

   struts2的action返回不再是结果类型,而是一个对象,这个对象返回给gwt后,由gwt进行相关的处理

我将部分的代码贴出来

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>HelloWorldStrutsGwt.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

 关于strust2.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC 
	"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
	"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<package name="helleWorld" extends="gwt-default">
		<action name="helloAction" class="org.flybird.struts2.action.HelloWorldAction"> 
			<interceptor-ref name="gwt"/>
		</action>
	</package>
</struts>

 关于xxxx.gwt.xml配置

<?xml version="1.0" encoding="UTF-8" standalone="no"?><module>

	<!-- Inherit the core Web Toolkit stuff.                  -->
	<inherits name="com.google.gwt.user.User"/>

	<!-- Specify the app entry point class.                   -->
	<entry-point class="org.flybird.gwt.client.HelloWorldStrutsGwt"/>
  
  	<inherits name="com.google.gwt.user.theme.standard.Standard"/>
  	<!-- <inherits name="com.google.gwt.user.theme.chrome.Chrome"/> -->
  	<!-- <inherits name="com.google.gwt.user.theme.dark.Dark"/> -->
  	  <inherits name="com.extjs.gxt.ui.GXT"/>

 </module>
 
package org.flybird.gwt.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

@RemoteServiceRelativePath("helloWorldRPC")
public interface HelloWorldRPC extends RemoteService {
	public String execute();
}

 

package org.flybird.gwt.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface HelloWorldRPCAsync {
	public void execute(AsyncCallback<String> callback);
}

 

package org.flybird.gwt.client;

import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.RootPanel;

public class HelloWorldStrutsGwt implements EntryPoint {

	public void onModuleLoad() {
		FormPanel formPanel = new FormPanel();
		// formPanel.setLayout();
		TextField<String> customerName = new TextField<String>();
		customerName.setFieldLabel("客户名称");
		Button save = new Button("保存");
		save.addSelectionListener(new SelectionListener<ComponentEvent>() {

			@Override
			public void componentSelected(ComponentEvent ce) {
				callAction();
				
			}
		});
		formPanel.add(customerName);
		formPanel.add(save);
		RootPanel.get().add(formPanel);
	}

	private void callAction() {
		HelloWorldRPCAsync service = (HelloWorldRPCAsync) GWT.create(HelloWorldRPC.class);
		AsyncCallback callback = new AsyncCallback() {
			public void onSuccess(Object result) {
				Window.alert(result.toString());
			}

			public void onFailure(Throwable caught) {
				Window.alert(caught.toString());
			}
		};
		ServiceDefTarget endpoint = (ServiceDefTarget) service;
		endpoint.setServiceEntryPoint("helloAction.action");
		service.execute(callback);
	}

}
 
package org.flybird.struts2.action;

public class HelloWorldAction {
	public String execute(){
		return "hello world i am studying gwt struts2";
	}

}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值