水仁博客

          上善若水,仁恕載物
          隨筆 - 11, 文章 - 0, 評論 - 4, 引用 - 0
          數據加載中……

          2008年6月8日

          SpringMVC 2.5 的HelloWorld

          首先,寫一個Bean

          package springmvc.one.web;

          import org.springframework.beans.factory.annotation.Autowired;
          import org.springframework.stereotype.Controller;
          import org.springframework.ui.Model;
          import org.springframework.ui.ModelMap;
          import org.springframework.validation.BindingResult;
          import org.springframework.web.bind.annotation.RequestMapping;
          import org.springframework.web.bind.annotation.RequestMethod;

          @Controller
          @RequestMapping("/hellOne.act")
          public class HelloOneAction { 

          @RequestMapping
          public String handleRequest(String user,Model model) { 
          System.out.println("用戶名:"+user); //GET/POST的入參
          model.addAttribute("user", user); //通過Session返回到界面的出參
          model.addAttribute("helloWord", "Hello");

          return "hellouser";

          }


          再寫一個JSP頁面hellouser.jsp,此頁面放在 WEB-INF/jsp 目錄下,代碼如下:

          <html> 
          <head><title>HelloPage</title></head> 
          <body> 
          Test this sample!
          <H1> ${helloWord}, ${user}!</H2> 
          </body>
          </html>


          接著看看web.xml的配置

          <?xml version="1.0" encoding="ISO-8859-1"?> 

          <web-app 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">

          <description>Spring 2.5 App</description> 
          <display-name>Spring App Examples</display-name> 

          <servlet> 
          <servlet-name>annomvc</servlet-name> 
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          <load-on-startup>2</load-on-startup> 
          </servlet> 

          <servlet-mapping> 
          <servlet-name>annomvc</servlet-name> 
          <url-pattern>*.act</url-pattern> 
          </servlet-mapping> 

          </web-app>


          最后就是,annomvc.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

          <context:component-scan base-package="springmvc.one.web"/>

          <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>

          </beans>


          好了,見一個Tomcat工程,在 tomcat 中運行,訪問下面連接,就可以運行了。

          http://localhost:8080/TOMCAT-PROJECT/hellOne.act?user=gjhuai

          posted @ 2008-09-27 14:31 水仁圭 閱讀(3477) | 評論 (1)編輯 收藏

          [專業]JS一些知識-0806081757


          JS的日期加減函數:

          function dateAdd(date,dayNum){
          var a = date.valueOf();
          a = a + dayNum * 24 * 60 * 60 * 1000;
          a = new Date(a);
          return a;
          }


          JS把字符串裝載到DOM對象:
          var doc = new ActiveXObject("MSxml2.DOMDocument");
          doc.loadXML( xmlStr);


          當JS的正則表達式的pattern需要動態構造時,需要使用RegExp類:
          patt=new RegExp(today.replace(/\-/g,"\\-")+"((.|\n|\r|\t)+)"+yesterday.replace(/\-/g,"\\-"),"gm");
          //patt=new RegExp("2008\-5\-26((.|\n)+)2008\-5\-25","gm");
          h = h.replace(patt,yesterday);
          而不能使用/dd/gm之類簡單的pattern




          posted @ 2008-06-08 17:58 水仁圭 閱讀(232) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 贵德县| 呼玛县| 嵩明县| 恩施市| 阳信县| 新乡县| 阿克| 望奎县| 嘉鱼县| 饶河县| 图们市| 建平县| 广德县| 盐城市| 沈丘县| 德州市| 灵山县| 龙门县| 遂昌县| 克什克腾旗| 丰顺县| 定南县| 北宁市| 平利县| 芒康县| 望奎县| 渝中区| 新野县| 临沭县| 杂多县| 锡林郭勒盟| 北海市| 叶城县| 哈尔滨市| 札达县| 西城区| 鄂伦春自治旗| 如东县| 崇义县| 平南县| 西林县|