struts2 如何与gwt整合,网上有很多的说明,可惜解决的问题不全面,首先我思考一下,gwt经过编译后生成js,它就不应该和我们的java程序进行混合,js就是js,java程序就java程序,我们要把2者独立起来,然后通过通过请求与响应进行交互,在将gwt进行独立起来后,可以就可以用自己喜欢的框架及技术进行 编程,比传说中的ssh+gwt。
在这里由于项目的需要,我做的是erp,技术是struts2 ,spring ,hibernate, jbpm, gwt ,所有先得考虑struts2与gwt交互问题,这个解决了。什么都好说了。
我将struts2与gwt如何整合贴出来。
web.xml <?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"> <display-name>Struts2-gwt</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>Index.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>struts2配置:
<?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="struts2-gwt" extends="struts-default" > <action name="saveAction " class="com.hzinfor.struts2.IndexAction"> </action> </package> </struts>
java类:
public class Customer { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
-------------------------------------------------
public class IndexAction extends ActionSupport { private Customer customer; @Override public String execute() throws Exception { System.out.println("the name is " + customer.getName()); return null; } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } }
-------------------------------------------------------------------------------
public class Index implements EntryPoint { public void onModuleLoad() { final FormPanel form = new FormPanel(); form.setMethod(Method.POST); form.setAction( "saveAction.action "); final TextField<String> name = new TextField<String>(); name.setFieldLabel( "名称"); name.setName( "customer.name"); name.setId("cutomer.name"); form.add(name); Button button = new Button("提交"); button.addSelectionListener(new SelectionListener<ComponentEvent>(){ @Override public void componentSelected(ComponentEvent ce) { form.submit(); }}); Button reset = new Button("重置"); reset.addSelectionListener(new SelectionListener<ComponentEvent>(){ @Override public void componentSelected(ComponentEvent ce) { form.reset(); }}); form.addButton(button); form.addButton(reset); RootPanel.get().add(form); } }
相关资源:浅论阴阳太极与UML建模