<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-126  評(píng)論-247  文章-5  trackbacks-0

    Spring Jar 包


    將需要用到的 Spring Jar 包拷貝進(jìn) GWT Java Project 當(dāng)中。具體位置是:war/WEB-INF/lib。注意:不能拷貝到 lib 的子目錄下,不然會(huì)報(bào)找不到類的錯(cuò)誤!
    選中 lib 下的 Jar 包,右鍵 ——> Build Path ——> Add to Build Path。

    配置 web.xml

    位置:war/WEB-INF/web.xml
    <?xml version="1.0" encoding="UTF-8"?>
      
      <!-- Spring JAR 包一定要拷貝在lib目錄底下(不能是lib的子目錄, 否則會(huì)報(bào)找不到類的錯(cuò)誤!!!) -->
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
        <param-value>classpath*:spring/*.xml</param-value>
      </context-param>
      
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <!-- DispatcherServlet Spring MVC 的核心, 充當(dāng)前端控制器, 負(fù)責(zé)將請(qǐng)求分發(fā)給 Spring MVC 控制器處理 -->
      <!-- servlet-name 配置好之后, 默認(rèn)的, DispatcherServlet 將使用 /WEB-INF/名稱-servlet.xml 作為 Spring 上下文使用 -->
      <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      
      <!-- / : 攔截處理所有請(qǐng)求, 會(huì)導(dǎo)致靜態(tài)文件無法被訪問(mvc:resources) -->
      <!-- *.suffix -->
      <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>*.json</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
      </servlet-mapping>
      
      <welcome-file-list>
        <welcome-file>GxtTutorial.html</welcome-file>
      </welcome-file-list>

    </web-app>

    Spring MVC 配置

    位置:war/WEB-INF/mvc-dispatcher-servlet.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc
    ="http://www.springframework.org/schema/mvc"
      xmlns:context
    ="http://www.springframework.org/schema/context"
      xsi:schemaLocation
    ="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    >
      
      <context:component-scan base-package="fan.tutorial.server" />
      <mvc:annotation-driven/>
      
      <!-- 內(nèi)部視圖解析器:渲染輸出的視圖路徑由 prefix + 邏輯視圖名稱 + suffix 組成 -->
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
          <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
          <value>.jsp</value>
        </property>
      </bean>
      
      <!-- 靜態(tài)資源的映射, Spring MVC 不處理 -->
      <mvc:resources mapping="/res/**" location="/resources/"/>
      
    </beans>

    Spring 配置

    位置:classpath
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context
    ="http://www.springframework.org/schema/context"
      xsi:schemaLocation
    ="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    >

      <!-- 開啟注解 -->
      <context:annotation-config/>
      <!-- 自動(dòng)掃描 -->
      <context:component-scan base-package="fan.tutorial.server"/>
      
    </beans>

    編寫測(cè)試?yán)?

    ExampleController

    package fan.tutorial.server.controller;

    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    @RequestMapping("/example")
    public class ExampleController {

        @RequestMapping("/input/{something}")
        public String inputSomething(Model model, @PathVariable String something){
            System.out.println("**************************");
            System.out.println(something);
            System.out.println("**************************");
            return null;
        }
    }

    Example

    package fan.tutorial.client.ui;

    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.event.MessageBoxEvent;
    import com.extjs.gxt.ui.client.widget.Info;
    import com.extjs.gxt.ui.client.widget.LayoutContainer;
    import com.extjs.gxt.ui.client.widget.MessageBox;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.http.client.Request;
    import com.google.gwt.http.client.RequestBuilder;
    import com.google.gwt.http.client.RequestCallback;
    import com.google.gwt.http.client.RequestException;
    import com.google.gwt.http.client.Response;
    import com.google.gwt.user.client.Element;

    public class Example extends LayoutContainer {

        @Override
        protected void onRender(Element parent, int index) {
            super.onRender(parent, index);
            
            MessageBox.prompt("Message", "Please input something.", new Listener<MessageBoxEvent>() {
                @Override
                public void handleEvent(MessageBoxEvent be) {
                    if(be.getButtonClicked().getItemId().equals(MessageBox.OK)){
                        String value = be.getValue();
                        String url = GWT.getHostPageBaseURL() + "example/input/" + value + ".json";
                        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
                        builder.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                        try {
                            builder.sendRequest(nullnew RequestCallback() {
                                @Override
                                public void onResponseReceived(Request request, Response response) {
                                    Info.display(" ", "數(shù)據(jù)提交成功!");
                                }
                                @Override
                                public void onError(Request request, Throwable exception) {
                                    MessageBox.alert("System Message", "數(shù)據(jù)提交失敗!", null);
                                }
                            });
                        } catch (RequestException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
        }
    }

    結(jié)果圖








      
    posted on 2014-06-08 18:05 fancydeepin 閱讀(1589) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 免费一看一级毛片| 国产在亚洲线视频观看| 免费无码又爽又刺激聊天APP| 亚洲天堂2016| 16女性下面扒开无遮挡免费| 亚洲日韩久久综合中文字幕| 国内精品99亚洲免费高清| 中文字幕视频免费| 高清免费久久午夜精品| 亚洲综合视频在线| 日韩电影免费在线观看视频| 亚洲av永久无码嘿嘿嘿| 免费又黄又爽的视频| 99re免费视频| 美景之屋4在线未删减免费 | 久久精品一本到99热免费| 亚洲天堂免费在线| 亚洲啪啪AV无码片| 日美韩电影免费看| 蜜臀AV免费一区二区三区| 免费无码一区二区| 国产成人精品日本亚洲网址| 国产中文在线亚洲精品官网| 最近免费中文字幕视频高清在线看| 久久er国产精品免费观看8| 亚洲中文字幕乱码熟女在线| 亚洲伦另类中文字幕| 亚洲欧洲中文日韩久久AV乱码| 中文字幕av无码无卡免费| 91亚洲精品第一综合不卡播放| 亚洲精品国产V片在线观看| 成人免费在线看片| 国产精品免费看久久久| 一级毛片高清免费播放| 亚洲av乱码中文一区二区三区| 亚洲婷婷综合色高清在线| 亚洲国产精彩中文乱码AV| 免费能直接在线观看黄的视频| 久久精品国产亚洲AV久| 久久久婷婷五月亚洲97号色| 亚洲精品午夜无码电影网|