国产a v无码专区亚洲av,337p日本欧洲亚洲大胆艺术,亚洲伦另类中文字幕http://www.tkk7.com/produ/category/54579.html<h2>見證學習的軌跡,記錄閃光的想法</h2>zh-cnWed, 01 Apr 2015 02:39:37 GMTWed, 01 Apr 2015 02:39:37 GMT60溫故知新:springMVC_02參數傳遞http://www.tkk7.com/produ/articles/424006.html都較瘦都較瘦Tue, 31 Mar 2015 15:56:00 GMThttp://www.tkk7.com/produ/articles/424006.htmlhttp://www.tkk7.com/produ/comments/424006.htmlhttp://www.tkk7.com/produ/articles/424006.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/424006.htmlhttp://www.tkk7.com/produ/services/trackbacks/424006.html

都較瘦 2015-03-31 23:56 發表評論
]]>
溫故知新:springMVC_01初步http://www.tkk7.com/produ/articles/424005.html都較瘦都較瘦Tue, 31 Mar 2015 15:55:00 GMThttp://www.tkk7.com/produ/articles/424005.htmlhttp://www.tkk7.com/produ/comments/424005.htmlhttp://www.tkk7.com/produ/articles/424005.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/424005.htmlhttp://www.tkk7.com/produ/services/trackbacks/424005.html1:類庫的引用,新建一個maven項目,將springMVC的依賴添加進來
1 <!-- springMVC dependency-->
2 <dependency>
3   <groupId>org.springframework</groupId>
4   <artifactId>spring-webmvc</artifactId>
5   <version>4.0.3.RELEASE</version>
6 </dependency>
2:在web.xml中添加springMVC的控制器
1   <servlet>
2       <servlet-name>demo</servlet-name>
3       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
4   </servlet>
5 
6   <servlet-mapping>
7       <servlet-name>demo</servlet-name>
8       <url-pattern>/</url-pattern>
9   </servlet-mapping>
3:添加springMVC的配置文件,注意:文件的名字需要是xxx-servlet,xxx就是剛才web.xml中添加的控制器的名稱
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
 4      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
 5      xmlns:util="http://www.springframework.org/schema/util"
 6      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
 7              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd  
 8              http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd              
 9              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
10 
11      <!-- 激活@Controller模式 -->
12      <mvc:annotation-driven />
13      
14      <!-- 對包中的所有類進行掃描,以完成Bean創建和自動依賴注入的功能 需要更改 -->
15      <context:component-scan base-package="com.demo.*" />
16  
17       <!-- 默認采用BeanNameViewResolver的請求解析方式,即
18           <bean name="/hello.html" class="XXXpackage.XXXclass"/>
19           的方式進行請求映射,該配置默認開啟,不寫亦可,這里采用注解映射
20        -->
21        
22       <!-- 注解方式的請求映射 -->
23      <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
24  
25       <!-- 視圖的映射,這里需要根據controller的返回值來確定視圖 -->
26      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
27          <property name="prefix">
28              <value>/WEB-INF/jsp/</value>
29          </property>
30          <property name="suffix">
31              <value>.jsp</value>
32          </property>
33      </bean>
34 
35 </beans>
36 
4:添加一個控制器
 1 package com.duyt.controllor;
 2 
 3 import org.springframework.stereotype.Controller;
 4 import org.springframework.web.bind.annotation.RequestMapping;
 5 
 6 //注明當前這個類是控制器,項目啟動時會被掃描
 7 @Controller
 8 //該類的請求映射,為"/"
 9 @RequestMapping("/")
10 public class HelloControllor {
11     
12     //該方法的請求映射,需要將類的請求映射和方法的請求映射拼接起來,也就是"/hello"(類的請求映射為"/")
13     @RequestMapping("/hello")
14     public String Hello(){
15         
16         //視圖的響應,根據配置文件的配置,會在WEB-INF/jsp文件夾中查找以hello為名稱,.jsp結尾的視圖文件
17         return "hello";
18     }
19 }
20 
視圖就省略了,以上就是使用springMVC的流程,這篇就不記錄其他相關的功能了,傳參,異常,文件上傳等功能后續再整理,這里就只是記錄一個最簡單的體驗案例。

都較瘦 2015-03-31 23:55 發表評論
]]>
溫故知新:struts2_09其他功能:異常的處理http://www.tkk7.com/produ/articles/419438.html都較瘦都較瘦Mon, 03 Nov 2014 02:37:00 GMThttp://www.tkk7.com/produ/articles/419438.htmlhttp://www.tkk7.com/produ/comments/419438.htmlhttp://www.tkk7.com/produ/articles/419438.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419438.htmlhttp://www.tkk7.com/produ/services/trackbacks/419438.html
Action:
 1 package demo.action;
 2 
 3 public class HelloWorld {
 4 
 5     public String execute() throws Exception {
 6         //模擬一個異常
 7         if (true) {
 8             throw new Exception("Exception test");
 9         }
10         return "success";
11     }
12     
13 }
14 
struts.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 <struts>
 6 
 7     <constant name="struts.devMode" value="true" />
 8     <package name="helloworld" extends="struts-default" namespace="/">
 9 
10         <global-results>
11             <!-- 指定一個頁面作為異常頁面 -->
12             <result name="error">/error.jsp</result>
13         </global-results>
14 
15         <global-exception-mappings>
16             <!-- 配置需要捕獲的異常類型,以及返回結果 -->
17             <exception-mapping result="error" exception="Exception" />
18         </global-exception-mappings>
19 
20         <action name="hello" class="demo.action.HelloWorld">
21             <result name="success">/helloWorld.jsp</result>
22         </action>
23 
24     </package>
25 
26 </struts> 
全局異常結果集的配置很簡便,可以配置一些404或者一些通用的異常頁面,在頁面中使用${exception.message}就可以獲得異常信息。

都較瘦 2014-11-03 10:37 發表評論
]]>
溫故知新:struts2_08其他功能:表單驗證http://www.tkk7.com/produ/articles/419427.html都較瘦都較瘦Mon, 03 Nov 2014 01:50:00 GMThttp://www.tkk7.com/produ/articles/419427.htmlhttp://www.tkk7.com/produ/comments/419427.htmlhttp://www.tkk7.com/produ/articles/419427.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419427.htmlhttp://www.tkk7.com/produ/services/trackbacks/419427.html閱讀全文

都較瘦 2014-11-03 09:50 發表評論
]]>
溫故知新:struts2_07其他功能:國際化http://www.tkk7.com/produ/articles/419400.html都較瘦都較瘦Sun, 02 Nov 2014 07:13:00 GMThttp://www.tkk7.com/produ/articles/419400.htmlhttp://www.tkk7.com/produ/comments/419400.htmlhttp://www.tkk7.com/produ/articles/419400.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419400.htmlhttp://www.tkk7.com/produ/services/trackbacks/419400.html
其實多語言問題,Java本身就提供了解決方案,util工具包中ResourceBundle就可以解決該問題,ResourceBundle的說明如下寫道
......
This allows you to write programs that can:
  • be easily localized, or translated, into different languages 
  • handle multiple locales at once 
  • be easily modified later to support even more locales
......
顯然,為了能使用國家化,我們需要為每一個需要使用的語言單獨配置他們的語言內容。分別新建中文和英文的語言配置文件置于src下
Message_zh.properties
1 username=\u7528\u6237\u540D(用戶名)
2 password=\u5BC6\u7801(密碼)
Message_en.properties
1 username=username
2 password=password
由于properties只支持iso-8859格式的編碼,所以在輸入中文的時候會有些問題,只是Eclipse自帶的properties編輯器可以進行可視化的文本輸入,不需要關注編碼。另外我們可以通過Java自帶的轉碼工具native2ascii進行轉碼。
測試類如下,getBundle方法接收兩個參數,第一個是BaseName,可以理解為資源的基礎名,第二個是語言碼,中文是zh,英文是en等等,測試類運行完畢之后會給出英文資源文件中username所對應的值,同理Locale設置為中文則輸出中文的值。所以資源文件我們以Message_en.properties這種格式來命名,其中en之后還可以添加下劃線跟第三個值區域碼,但是一般可以省略。
 1 package demo.i18n;
 2 
 3 import java.util.Locale;
 4 import java.util.ResourceBundle;
 5 
 6 public class I18nTest {
 7 
 8     public static void main(String[] args) {
 9         ResourceBundle rb = ResourceBundle.getBundle("Message", Locale.ENGLISH);
10         System.out.println(rb.getString("username"));
11     }
12     
13 }
14 

基于上面的內容,struts2使用它們配置全局國際化資源,在struts.xml中添加國家化的配置,其中value就是資源的基礎名
1 <constant name="struts.custom.i18n.resources" value="Message" />
之后,在頁面上使用struts2的標簽進行對應語言內容的顯示,當然,顯示哪種語言需要顯式的將語言碼作為參數傳入,請求地址需要寫作/XXX.action?request_locale=en
1 全局國際化<br/>
2 <s:text name="username"/><br/>
除了全局國際化的配置,struts2還提供了包范圍和action范圍的國際化,其中包范圍的國際化,需要將資源文件命名為“package_語言碼.properties”的形式,然后置于需要的包下,struts2會優先取得較小范圍的國際化資源文件,同時定義全局國際化資源和包國際化資源,那么包范圍的資源會優先生效。至于action范圍的國際化,因為國際化在日常的開發中本來用的就不是很多,就算真的碰到需要雙語開發的情況,或許也是做兩套頁面,或者直接做兩套網站,除非是那種跨國性質的“因特噗啦一吇”,否則不要說struts2的全局國際化的使用,針對包范圍和action范圍的國際化,都是少有問津。









都較瘦 2014-11-02 15:13 發表評論
]]>
溫故知新:struts2_06其他功能:攔截器http://www.tkk7.com/produ/articles/419384.html都較瘦都較瘦Sun, 02 Nov 2014 01:28:00 GMThttp://www.tkk7.com/produ/articles/419384.htmlhttp://www.tkk7.com/produ/comments/419384.htmlhttp://www.tkk7.com/produ/articles/419384.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419384.htmlhttp://www.tkk7.com/produ/services/trackbacks/419384.html struts2的攔截器其實和過濾器是一個概念,雖然自定義的過濾器用的不多,但是struts2的核心功能都是用攔截器來實現的,異常捕獲,參數綁定,和國際化等等。

寫一個最簡單的過濾器的例子,感受一下自定義過濾器的使用就好。
先上action
 1 package demo.action;
 2 
 3 public class InterceptorDemo {
 4     
 5     private String name;
 6     
 7     public String execute(){
 8         System.out.println("我是Execute的方法");
 9         System.out.println("name:" + name);
10         return "success";
11     }
12     
13     //get/set方法略
14     
15 }
16 
創建一個interceptor只需要新建一個類,繼承struts2的AbstractInterceptor,重寫intercept方法
 1 package demo.interceptor;
 2 
 3 import com.opensymphony.xwork2.ActionInvocation;
 4 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 5 
 6 public class InterceptorDemo extends AbstractInterceptor{
 7 
 8     private static final long serialVersionUID = -1739072578539674220L;
 9 
10     @Override
11     public String intercept(ActionInvocation invocation) throws Exception {
12         
13         System.out.println("我是一個炫酷的攔截器");
14         
15         //校驗用戶是否登陸等操作
16         //ServletActionContext.getContext().getSession()...
17         
18         //校驗用戶是否有權限訪問等操作
19         //invocation.getProxy().getActionName()...
20         
21         return invocation.invoke();
22     }
23 
24 }
25 
如此一來,攔截器就創建好了,接下來就是對攔截器的配置,看到struts.xml
 1    <package name="interceptorDemo" extends="struts-default" namespace="/">
 2    
 3        <!-- 需要在包內聲明攔截器,之后可以定義在action中定義對聲明攔截器的引用 -->
 4        <interceptors>
 5            <interceptor name="InterceptorDemo" class=demo.interceptor.InterceptorDemo"/>
 6        </interceptors>
 7    
 8        <!-- 在指定的action中使用指定的攔截器 -->
 9       <action name="interceptorDemo" 
10             class="demo.action.InterceptorDemo" 
11             method="execute">
12             <interceptor-ref name="InterceptorDemo"/>
13       </action>
14
15    </package>
將定義好的攔截器添加到某個action的定義中,讓攔截器攔截對應的action,但如果如上述那樣去配置的話,除了自定義攔截器的功能,struts2 的攔截器功能都會失效,action中的name值根本拿不到。配置中的每個包都會繼承struts-default這個包,簡單看一下struts-default.xml這個文件
 1 <interceptor-stack name="defaultStack">
 2   <interceptor-ref name="exception"/>
 3  <interceptor-ref name="alias"/>
 4  <interceptor-ref name="servletConfig"/>
 5  <interceptor-ref name="i18n"/>
 6  <interceptor-ref name="prepare"/>
 7  <interceptor-ref name="chain"/>
 8  <interceptor-ref name="scopedModelDriven"/>
 9  <interceptor-ref name="modelDriven"/>
10  <interceptor-ref name="fileUpload"/>
11  <interceptor-ref name="checkbox"/>
12  <interceptor-ref name="multiselect"/>
                    ...
     <interceptor-ref name="debugging"/>
    </interceptor-stack>
                    ...
    <default-interceptor-ref name="default-stack"/>
                    ...
上述就是部分配置,定義了默認的攔截器棧,也就是一組攔截器,從名字就可以看出很多功能都由攔截器完成,所以,自定義的攔截器也需要引用這一組攔截器,需要在配置中添加默認攔截器棧
1 <action name="interceptorDemo" 
2             class="org.duyt.action.InterceptorDemo" 
3             method="execute">
4             <interceptor-ref name="InterceptorDemo"/>
5             <interceptor-ref name="defaultStack"/>
6 </action>
或者定義一組攔截器棧
 1        <interceptors>
 2            <interceptor name="InterceptorDemo" class="demo.interceptor.InterceptorDemo"/>
 3         
 4            <!-- 聲明的攔截器棧一定要引用defaultStack,不然struts2無法發揮作用,參數封裝等最基本的功能都會失效 -->
 5            <interceptor-stack name="selfStack">
 6                <interceptor-ref name="InterceptorDemo"/>
 7                <interceptor-ref name="defaultStack"/>
 8            </interceptor-stack>
 9        </interceptors>
10    
11          <!-- 在指定的action中使用指定的攔截器 -->
12       <action name="interceptorDemo" 
13             class="demo.action.InterceptorDemo" 
14             method="execute">
15             <interceptor-ref name="selfStack"/>
16       </action>
這樣,自定義的攔截器就能融入到完整的功能之中。


都較瘦 2014-11-02 09:28 發表評論
]]>
溫故知新:struts2_05其他功能:文件上傳http://www.tkk7.com/produ/articles/419380.html都較瘦都較瘦Sat, 01 Nov 2014 14:10:00 GMThttp://www.tkk7.com/produ/articles/419380.htmlhttp://www.tkk7.com/produ/comments/419380.htmlhttp://www.tkk7.com/produ/articles/419380.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419380.htmlhttp://www.tkk7.com/produ/services/trackbacks/419380.html首先,文件上傳的表單必須是以下設置
1 <form action="XXX" method="post" enctype="multipart/form-data">
設置完畢之后,看一下servlet的post的方法的設置
 1 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 2         
 3         request.setCharacterEncoding("utf-8");
 4         
 5         // 首先需要確認,到底是不是文件上傳的請求,
 6         boolean isMultipart = ServletFileUpload.isMultipartContent(request);
 7         
 8         if (isMultipart) {
 9             // 創建一個文件處理對象
10             ServletFileUpload upload = new ServletFileUpload();
11             InputStream is = null;
12             FileOutputStream os = null;
13             try {
14                 // 解析請求中的所有元素
15                 FileItemIterator iter = upload.getItemIterator(request);
16                 while (iter.hasNext()) {
17                     FileItemStream item = iter.next();
18                     is = item.openStream();
19                     //是否是表單域
20                     if (item.isFormField()) {
21                         //其他操作,保存參數等
22                     } else {
23                         //不是表單域則保存文件
24                         String path = request.getSession().getServletContext().getRealPath("/");
25                         path = path + "/upload/" + item.getName();
26                         os = new FileOutputStream(path);
27                         //流讀寫
28                         byte[] buf = new byte[1024];
29                         while(is.read(buf)>0){
30                             os.write(buf);
31                         }
32                     }
33 
34                 }
35             } catch (FileUploadException e) {
36                 e.printStackTrace();
37             } finally{
38                 if (is != null) {
39                     is.close();
40                 }
41                 if (os != null) {
42                     os.close();
43                 }
44             }
45         }
46     }
洋洋灑灑一大堆,struts2封裝了這些通用的處理,我們可以按照struts2的風格來獲取要上傳文件的對象,直接寫一個多文件上傳的例子吧
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>文件上傳</title>
 8 </head>
 9 <body>
10     <form action="FileUpload" method="post" enctype="multipart/form-data">
11         文件上傳測試:<br>
12         <input type="file" name="text"/><br>
13         <input type="file" name="text"/><br>
14         <input type="file" name="text"/><br>
15         <input type="submit" value="提交">
16     </form>
17 </body>
18 </html>
action為
 1 package demo.fileUpload;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 import org.apache.commons.io.FileUtils;
 7 import org.apache.struts2.ServletActionContext;
 8 
 9 public class FileUpload {
10     
11     //文件接收數組如果是單文件上傳,那就不需要定義數組了,定義單個文件對象就行
12     private File text[];
13     //對應的文件名,這里的文件名是“名字.后綴”的形式,這個屬性的命名需要是“文件屬性的名字”+FileName。
14     private String[] textFileName;
15     //對應的文件類型,是文件的真實類型,比如“text/plain”這個屬性的命名需要是“文件屬性的名字”+ContentType
16     private String[] textContentType;
17 
18     public String execute() throws IOException{
19         
20         String dir = "";
21         File file = null;
22         
23         for (int i = 0; i < text.length; i++) {
24             //創建要新建的文件位置
25             dir = ServletActionContext.getServletContext().getRealPath("/"+  "/upload/" + textFileName[i];
26             file = new File(dir);
27             //保存文件
28             if (!file.exists()) {
29                 //使用common.io工具包保存文件
30                 FileUtils.copyFile(text[i], file);
31             }
32         }
33         
34         return "success";
35     }
36
37}


都較瘦 2014-11-01 22:10 發表評論
]]>
溫故知新:struts2_04常用標簽http://www.tkk7.com/produ/articles/419345.html都較瘦都較瘦Fri, 31 Oct 2014 09:54:00 GMThttp://www.tkk7.com/produ/articles/419345.htmlhttp://www.tkk7.com/produ/comments/419345.htmlhttp://www.tkk7.com/produ/articles/419345.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419345.htmlhttp://www.tkk7.com/produ/services/trackbacks/419345.html
首先,為了能夠使用struts2提供的標簽,我們需要先添加標簽的引用
在JSP頁面上添加,uri的具體值可以在struts2包的META-INF的struts-tags.tld文件中查看
<%@taglib prefix="s" uri="/struts-tags"%>
先看一下最常用的
1 <s:property value="str" default="" escapeCsv="" escapeHtml="" escapeJavaScript="" escapeXml=""/>
和EL表達式${str}的作用類似,展示動態數據,只不過property標簽強化了很多功能,可以免去判斷直接設定默認值,忽略cvs,html等內容,雖然struts2的標簽不支持EL表達式但是有一種類似的寫法
1 <s:property value="%{str}"/>

其次是流程控制標簽
1 <s:if test="condition != null">
2     <!--你的代碼-->
3 </s:if>
test的內容可以使用OGNL表達式獲取,除了Java那些常規的判斷寫法,可以將&&可以寫作and,||可以寫作or,和JSTL的判斷類似,都有自己的個性

之后是迭代標簽,迭代標簽可以說是struts2標簽中最常用的標簽之一,不僅是因為列表功能很常見,而且迭代標簽給出了很好用的功能
假定vals是個list,那么遍歷這個list
1 <s:iterator value="vals" var="val" begin="0" end="5" status="st" step="2">
2     <s:property value="val"/>-<s:property value="#st.index"/>-<s:property value="#st.count"/><br>
3 </s:iterator>
begin和end屬性可以靈活的設定遍歷的區間,step則是步進的長度,但是step必須在指定了begin之后才生效,特別要說明status這個屬性,聲明了st之后,便可以獲得當前遍歷的下標或者行號,這樣一來就可以根據需求執行其他的操作。var屬性則聲明了當前的遍歷對象,使用var屬性之后,會在ValueStack中的root和ActionContext中各生成一份當前對象,所以也可以寫為<s:property value="#val"/>,如果不聲明var屬性,則只會在root中生成一份當前對象,是否聲明var屬性,取決于當前遍歷的元素類型,比如vals是一個user列表,那么迭代標簽會把當前迭代的user對象置于棧頂,循環內直接寫<s:property value="name"/>就可以獲取user的name值,無需聲明var屬性。

假定vals是個map,那么遍歷這個map
<s:iterator value="mapVals" var="val" begin="0" end="5" status="st" step="2">
2     <s:property value="mapVals.get(#val.getKey())"/>-<s:property value="#st.index"/>-<s:property value="#st.count"/><br>
</s:iterator>
或者寫為
<s:iterator value="mapVals.keySet()" var="keyId" begin="0" end="5" status="st" step="2">
2     <s:property value="mapVals.get(#keyId)"/>-<s:property value="#st.index"/>-<s:property value="#st.count"/><br>
</s:iterator>

一些其他的表單標簽
1 <s:textfield label="username" name="%{user.username}"/>
2 <s:checkboxlist name="name" label="多選框"  list="#{'1':'Nick','2':'lily','3':'Mary' }" listKey="key" listValue="value" value="#{'1','2'}"/>
3 <s:radio label="Conutry" name="Conutry" value="2" list="#{'1':'中國','2':'美國','3':'俄羅斯' }" listKey="key" listValue="value"/>
4 <s:select list="users" label="姓名" value="1" listKey="id" listValue="username" headerKey="-1" headerValue="請選擇"/>
這些標簽雖然能很好的完成任務,但是不怎么靈活,一般來說前端的這些控件或多或少的都需要的添加自定義的樣式,所以這些標簽出現的機會比較少,只是簡單記錄一下。
還有很多其他的標簽,比如form等,HTML自帶標簽完全可以滿足一般需求。
這里特別提一下兩個工具類的標簽,其中格式化時間的date標簽用的比較頻繁,其次格式化數字的標簽number,可以用來截取數字長度,四舍五入等操作
1 <s:date name="time" format="yyyy-MM-dd"/>
2 <s:number name="money"/>





都較瘦 2014-10-31 17:54 發表評論
]]>
溫故知新:struts2_03參數的傳遞http://www.tkk7.com/produ/articles/419290.html都較瘦都較瘦Thu, 30 Oct 2014 08:38:00 GMThttp://www.tkk7.com/produ/articles/419290.htmlhttp://www.tkk7.com/produ/comments/419290.htmlhttp://www.tkk7.com/produ/articles/419290.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419290.htmlhttp://www.tkk7.com/produ/services/trackbacks/419290.html閱讀全文

都較瘦 2014-10-30 16:38 發表評論
]]>
溫故知新:struts2_02請求和處理的映射http://www.tkk7.com/produ/articles/419191.html都較瘦都較瘦Wed, 29 Oct 2014 16:38:00 GMThttp://www.tkk7.com/produ/articles/419191.htmlhttp://www.tkk7.com/produ/comments/419191.htmlhttp://www.tkk7.com/produ/articles/419191.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419191.htmlhttp://www.tkk7.com/produ/services/trackbacks/419191.html
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 <struts>
 6 
 7    <constant name="struts.action.extension" value="action,," /><!-- 請求后綴名-->  
 8    <package name="helloworld" extends="struts-default" namespace="/"><!-- struts-default這個包是一定要繼承的,否則struts很多重要功能會失效-->
 9       <action name="hello" <!-- action的名稱,namespace的值連接/hello表示請求該action  -->
10             class="demo.action.HelloWorld"><!-- class表示該action的位置,在action的配置中,如果不指定調用哪個方法,則默認調用execute方法  -->
11             <result name="success">/helloWorld.jsp</result><!-- action的返回結果,以及相應的視圖  -->
12       </action>
13    </package>
14 
15 </struts>
就是一種方式。這個配置中,就已經能很明顯的看出action和url之間的關系,只是這段配置沒有指明具體調用action中的哪個方法,所有默認調用了execute方法,雖然比較笨拙,但是這可以記為配置映射的第一個方法。需要特別一提的是struts.action.extension配置,它代表了action的后綴名,逗號隔開。也就是說,它指定了哪些結尾的請求為struts請求,默認是action和空結尾的請求。

方法一:
一個action只對應一個請求,默認調用execute方法,這樣,為了滿足業務需求,package中就會出現大量的action配置。實際開發中,除非這個請求進行的操作非常多,以至于書寫的代碼幾千行,甚至上萬行,否則一般不會這么配置,就算真的出現這樣的情況,也極有可能和其他配置方式混搭使用,單獨使用的比較少。
優點:配置簡單明了,而且action中只有一個方法,方便閱讀
缺點:會出現大量的action配置,大量的action類

方法二:
為了讓一個action能夠對應多個請求,可以在方法一的基礎上為action的配置添加method屬性
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 <struts>
 6 
 7    <package name="helloworld" extends="struts-default" namespace="/">
 8       <action name="hello" method="method01"
 9             class="demo.action.HelloWorld">
10             <result name="success">/helloWorld.jsp</result>
11       </action>
12    </package>
13 
14 </struts>
如此一來,action中的method01方法就會對應/hello請求。
優點:可以減少action類的數量
缺點:還是有大量的配置!!

方法三:
這種請求和處理的映射有點類似于將方法名當做參數來傳遞,struts.xml的配置和方法一一致,無需更改,只是在發送請求的時候需要將請求的方法一并發送,原始的請求是/hello,而連帶方法名的請求是/hello!hello,或者還可以寫/hello?method:hello(假定Helloworld類中有hello方法),這樣一來,就是直接調用hello方法來完成處理。
優點:不僅可以完成一個action和多個請求的映射,還能減少action的配置,僅僅只是額外配置action的result即可
缺點:地址注意不能寫錯,實際開發中不常用,或許只是看起來請求地址怪怪的。。。但依然是個不錯的配置方式

方法四:
基于通配符的映射
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 <struts>
 6 
 7    <package name="helloworld" extends="struts-default" namespace="/">
 8       <action name="*_*" 
 9             class="demo.action.{1}action" method="{2}">
10             <result name="success">/{1}/{2}.jsp</result>
11       </action>
12    </package>
13 
14 </struts>
顯而易見,任何形式的“XX_XX”請求都會得到映射,{1}代表第一個*的值,{2}代表第二個,以此類推,最主要的是,一定要從action的名稱,到action內的方法,直至最后響應視圖的位置,都要好好的在請求中寫好。基于通配符的配置方式顯得十分靈活,但也要求十分的細心,是一種能同時簡化action類和配置內容的映射方式。這里要特別提到result的結果,結果可以是struts提供的SUCCESS,ERROR等但不限于這些返回結果,自定義的返回結果只要有對應的相應視圖即可。
優點:配置靈活,精簡
缺點:配置時要求仔細,使用統一的規則,所謂的“約定優于配置”

實際開發中,根據各個配置方式的優缺點自行選擇,配置沒有絕對的好壞





都較瘦 2014-10-30 00:38 發表評論
]]>
溫故知新:struts2_01整體流程感受http://www.tkk7.com/produ/articles/419171.html都較瘦都較瘦Wed, 29 Oct 2014 07:52:00 GMThttp://www.tkk7.com/produ/articles/419171.htmlhttp://www.tkk7.com/produ/comments/419171.htmlhttp://www.tkk7.com/produ/articles/419171.html#Feedback0http://www.tkk7.com/produ/comments/commentRss/419171.htmlhttp://www.tkk7.com/produ/services/trackbacks/419171.html
環境如下
系統:64位win7


測試環境:



先從一個helloworld的簡單案例開始吧
新建一個maven項目,選擇


其實不論使用哪個框架技術,都無非三步走,import,config,run,首先,我們import
因為使用maven來管理項目,所以直接添加struts2的依賴到pom.xml
    <dependency>
        
<groupId>org.apache.struts</groupId>
        
<artifactId>struts2-core</artifactId>
        
<version>2.3.7</version>
    </dependency>
之后,我們開始config,具體配置哪些呢,首先要讓struts2去過濾請求,那么肯定要在web.xml中配置struts2的過濾器,然后還需要讓struts2知道請求和控制器之間的關系,那么肯定還需要再給struts2單獨進行配置。
首先添加struts2的過濾器到web.xml中
    <filter>
      
<filter-name>struts2</filter-name>
      
<filter-class>
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      
</filter-class>
   
</filter>
   
<filter-mapping>
      
<filter-name>struts2</filter-name>
      
<url-pattern>/*</url-pattern>
   </filter-mapping>

其次添加struts2的配置struts.xml,特別說一下constant的name值是配置在org.apache.struts.default.properties中的,還有其他常用的常量,比如struts.action.extension=action,,,請求后綴等
配置頭部的dtd在jar包中會有struts-2.X.dtd的配置,也不用到處搜索了。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd"
>
<struts>

   
<constant name="struts.devMode" value="true" /><!-- 開發模式開啟,能夠顯示更詳細的異常信息-->  
   <package name="helloworld" extends="struts-default" namespace="/"><!-- struts-default這個包是一定要繼承的,否則struts很多重要功能會失效-->
      
<action name="hello" <!-- action的名稱,namespace的值連接/hello表示請求該action  -->
            class
="demo.action.HelloWorld"><!-- class表示該action的位置,在action的配置中,如果不指定調用哪個方法,則默認調用execute方法  -->
            
<result name="success">/helloWorld.jsp</result><!-- action的返回結果,以及相應的視圖  -->
      
</action>
   
</package>

</struts>

action的內容
package demo.action;

public class HelloWorld {
    
public String execute() {
        System.out.println(
"Hello Struts2");
        
return "success";
    }
}

整個配置的過程就是這樣了,非常簡易。


都較瘦 2014-10-29 15:52 發表評論
]]>
主站蜘蛛池模板: 久久久久亚洲?V成人无码| 久久亚洲成a人片| 伊人久久免费视频| 亚洲av第一网站久章草| 亚洲国产成人久久综合一 | 国产精品久久久久久久久免费| 91av免费在线视频| 亚洲av无码日韩av无码网站冲| 亚洲一区电影在线观看| 久久久综合亚洲色一区二区三区| 亚洲国产高清精品线久久| 成人毛片免费视频| 成年免费大片黄在线观看岛国| 无码一区二区三区免费| 中文字幕高清免费不卡视频| 特级毛片aaaa级毛片免费| 中文无码亚洲精品字幕| 亚洲国产美女在线观看 | 午夜免费啪视频在线观看 | 国产精品黄页在线播放免费| 国产人在线成免费视频| 老汉精品免费AV在线播放| 成全视频免费观看在线看| 国产综合免费精品久久久| xxxxx做受大片在线观看免费| 国产精品亚洲精品爽爽| 亚洲成a人片在线观看天堂无码| 亚洲情A成黄在线观看动漫软件 | av成人免费电影| a在线视频免费观看在线视频三区| 韩国亚洲伊人久久综合影院| 亚洲精品乱码久久久久久V| 在线综合亚洲欧洲综合网站| 亚洲 欧洲 日韩 综合在线| 亚洲不卡视频在线观看| 中文字幕亚洲男人的天堂网络| 亚洲a视频在线观看| 亚洲va久久久久| 亚洲AV无码一区二区一二区| WWW亚洲色大成网络.COM | 精品无码国产污污污免费|