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

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

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

    隨筆-34  評(píng)論-1965  文章-0  trackbacks-0

    CRUD是Create(創(chuàng)建)、Read(讀取)、Update(更新)和Delete(刪除)的縮寫,它是普通應(yīng)用程序的縮影。如果您掌握了某框架的CRUD編寫,那么意味可以使用該框架創(chuàng)建普通應(yīng)用程序了,所以大家使用新框架開發(fā)OLTP(Online Transaction Processing)應(yīng)用程序時(shí),首先會(huì)研究一下如何編寫CRUD。這類似于大家在學(xué)習(xí)新編程語言時(shí)喜歡編寫“Hello World”。

    本文旨在講述Struts 2上的CRUD開發(fā),所以為了例子的簡單易懂,我不會(huì)花時(shí)間在數(shù)據(jù)庫的操作上。取而代之的是一個(gè)模擬數(shù)據(jù)庫的哈希表(Hash Map)。

    具體實(shí)現(xiàn)

    首先,讓我們看看的“冒牌”的DAO(Data Access Object,數(shù)據(jù)訪問對(duì)象),代碼如下:

    package tutorial.dao;

    import java.util.Collection;
    import java.util.concurrent.ConcurrentHashMap;
    import java.util.concurrent.ConcurrentMap;

    import tutorial.model.Book;

    public class BookDao {
       
    private static final BookDao instance;
       
    private static final ConcurrentMap<String, Book> data;
       
       
    static {
           instance
    = new BookDao();
           data
    = new ConcurrentHashMap<String, Book>();
           data.put(
    "978-0735619678", new Book("978-0735619678", "Code Complete, Second Edition", 32.99));
           data.put(
    "978-0596007867", new Book("978-0596007867", "The Art of Project Management", 35.96));
           data.put(
    "978-0201633610", new Book("978-0201633610", "Design Patterns: Elements of Reusable Object-Oriented Software", 43.19));
           data.put(
    "978-0596527341", new Book("978-0596527341", "Information Architecture for the World Wide Web: Designing Large-Scale Web Sites", 25.19));
           data.put(
    "978-0735605350", new Book("978-0735605350", "Software Estimation: Demystifying the Black Art", 25.19));
       }

       
       
    private BookDao() {}
       
       
    public static BookDao getInstance() {
           
    return instance;
       }

       
       
    public Collection<Book> getBooks() {
           
    return data.values();
       }

       
       
    public Book getBook(String isbn) {
           
    return data.get(isbn);
       }

       
       
    public void storeBook(Book book) {
           data.put(book.getIsbn(), book);
       }

           
       
    public void removeBook(String isbn) {
           data.remove(isbn);
       }

       
       
    public void removeBooks(String[] isbns) {
           
    for(String isbn : isbns) {
               data.remove(isbn);
           }

       }

    }
    清單1 src/tutorial/dao/BookDao.java

    以上代碼相信不用解釋大家也清楚,我使用ConcurrentMap數(shù)據(jù)結(jié)構(gòu)存儲(chǔ)Book對(duì)象,這主要是為了方便檢索和保存Book對(duì)象;另外,我還將data變量設(shè)為靜態(tài)唯一來模擬應(yīng)用程序的數(shù)據(jù)庫。

    接下來是的數(shù)據(jù)模型Book類,代碼如下:

    package tutorial.model;

    public class Book {
       
    private String isbn;
       
    private String title;
       
    private double price;
       
       
    public Book() {        
       }

       
       
    public Book(String isbn, String title, double price) {
           
    this.isbn = isbn;
           
    this.title = title;
           
    this.price = price;
       }


       
    public String getIsbn() {
           
    return isbn;
       }


       
    public void setIsbn(String isbn) {
           
    this.isbn = isbn;
       }


       
    public double getPrice() {
           
    return price;
       }


       
    public void setPrice(double price) {
           
    this.price = price;
       }


       
    public String getTitle() {
           
    return title;
       }


       
    public void setTitle(String title) {
           
    this.title = title;
       }
       
    }
    清單2 src/tutorial/model/Book.java

    Book類有三個(gè)屬性isbn,、title和price分別代表書籍的編號(hào)、名稱和價(jià)格,其中編號(hào)用于唯一標(biāo)識(shí)書籍(相當(dāng)數(shù)據(jù)庫中的主鍵)。

    然后,我們?cè)賮砜纯碅ction類的代碼:

    package tutorial.action;

    import java.util.Collection;

    import tutorial.dao.BookDao;
    import tutorial.model.Book;

    import com.opensymphony.xwork2.ActionSupport;

    public class BookAction extends ActionSupport {
       
    private static final long serialVersionUID = 872316812305356L;
       
       
    private String isbn;
       
    private String[] isbns;
       
    private Book book;
       
    private Collection<Book> books;
       
    private BookDao dao =  BookDao.getInstance();
           
       
    public Book getBook() {
           
    return book;
       }


       
    public void setBook(Book book) {
           
    this.book = book;
       }


       
    public String getIsbn() {
           
    return isbn;
       }


       
    public void setIsbn(String isbn) {
           
    this.isbn = isbn;
       }


       
    public String[] getIsbns() {
           
    return isbns;
       }


       
    public void setIsbns(String[] isbns) {
           
    this.isbns = isbns;
       }

           
       
    public Collection<Book> getBooks() {
           
    return books;
       }


       
    public void setBooks(Collection<Book> books) {
           
    this.books = books;
       }


       
    public String load() {
           book
    = dao.getBook(isbn);
           
    return SUCCESS;
       }


       
    public String list() {
           books
    = dao.getBooks();
           
    return SUCCESS;
       }

           
       
    public String store() {
           dao.storeBook(book);
           
    return SUCCESS;
       }

       
       
    public String remove() {
           
    if(null != isbn) {
               dao.removeBook(isbn);
           }
    else {
               dao.removeBooks(isbns);
           }

           
    return SUCCESS;
       }

    }
    清單3 src/tutorial/action/BookAction.java

    BookAction類中屬性isbn用于表示待編輯或刪除的書籍的編號(hào),屬性isbns用于表示多個(gè)待刪除的書籍的編號(hào)數(shù)組,屬性book表示當(dāng)前書籍,屬性books則表示當(dāng)前的書籍列表。BookAction有四個(gè)Action方法分別是load、list、store和remove,也即是CRUD都集中在BookAction中實(shí)現(xiàn)。

    再下來是Action的配置代碼:

    <?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_CRUD_DEMO" extends="struts-default" namespace="/Book">
           
    <action name="List" class="tutorial.action.BookAction" method="list">
               
    <result>List.jsp</result>
           
    </action>
           
    <action name="Edit" class="tutorial.action.BookAction" method="load">
               
    <result>Edit.jsp</result>
           
    </action>
           
    <action name="Store" class="tutorial.action.BookAction" method="store">
               
    <result type="redirect">List.action</result>
           
    </action>
           
    <action name="Remove" class="tutorial.action.BookAction" method="remove">
               
    <result type="redirect">List.action</result>
           
    </action>
       
    </package>
    </struts>
    清單4 src/struts.xml

    以上的配置中,我使用了四個(gè)Action定義。它們都在“/Book”名值空間內(nèi)。這樣我就可以分別通過“http://localhost:8080/Struts2_CRUD/Book/List.action”、“http://localhost:8080/Struts2_CRUD/Book/Edit.action”、“http://localhost:8080/Struts2_CRUD/Book/Store.action”和“http://localhost:8080/Struts2_CRUD/Book/Remove.action”來調(diào)用BookAction的四個(gè)Action方法進(jìn)行CRUD操作。當(dāng)然,這只是個(gè)人喜好,你大可以只定義一個(gè)Action(假設(shè)其名稱為“Book”),之后通過“http://localhost:8080/Struts2_CRUD/Book!list.action”的方式來訪問,詳細(xì)做法請(qǐng)參考《Struts 2.0的Action講解》。另外,我由于希望在完成編輯或刪除之后回到列表頁,所以使用類型為redirect(重定向)的result。

    下面是列表頁面的代碼:

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       
    <title>Book List</title>
       
    <style type="text/css">
            table
    {
                border
    : 1px solid black;
                border-collapse
    : collapse;
           
    }
            
            table thead tr th
    {
                border
    : 1px solid black;
                padding
    : 3px;
                background-color
    : #cccccc;
           
    }
            
            table tbody tr td
    {
                border
    : 1px solid black;
                padding
    : 3px;
           
    }
       
    </style>
    </head>
    <body>    
       
    <h2>Book List</h2>
       
    <s:form action="Remove" theme="simple">
           
    <table cellspacing="0">
               
    <thead>
                   
    <tr>
                       
    <th>Select</th>
                       
    <th>ISBN</th>
                       
    <th>Title</th>
                       
    <th>Price</th>
                       
    <th>Operation</th>
                   
    </tr>
               
    </thead>
               
    <tbody>
                   
    <s:iterator value="books">
                       
    <tr>
                           
    <td><input type="checkbox" name="isbns" value='<s:property value="isbn" />' /></td>
                           
    <td><s:property value="isbn" /></td>
                           
    <td><s:property value="title" /></td>
                           
    <td>$<s:property value="price" /></td>
                           
    <td>
                               
    <a href='<s:url action="Edit"><s:param name="isbn" value="isbn" /></s:url>'>
                                    Edit
                               
    </a>
                               
    &nbsp;
                               
    <a href='<s:url action="Remove"><s:param name="isbn" value="isbn" /></s:url>'>
                                    Delete
                               
    </a>
                           
    </td>
                       
    </tr>
                   
    </s:iterator>
               
    </tbody>
           
    </table>
           
    <s:submit value="Remove" /><a href="Edit.jsp">Add Book</a>
       
    </s:form>    
    </body>
    </html>
    清單5 WebContent\Book\List.jsp

    以上代碼,值得注意的是在<s:form>標(biāo)簽,我設(shè)置了theme屬性為“simple”,這樣可以取消其默認(rèn)的表格布局。之前,有些朋友問我“如果不希望提交按鈕放在右邊應(yīng)該怎樣做?”,上述做汗是答案之一。當(dāng)然,更佳的做法自定義一個(gè)theme,并將其設(shè)為默認(rèn)應(yīng)用到整個(gè)站點(diǎn),如此一來就可以得到統(tǒng)一的站點(diǎn)風(fēng)格。我會(huì)在以后的文章中會(huì)對(duì)此作詳細(xì)的描述。

    編輯或添加書籍的頁面代碼如下:

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       
    <title>Book</title>
    </head>
    <body>    
       
    <h2>
           
    <s:if test="null == book">
                Add Book
           
    </s:if>
           
    <s:else>
                Edit Book
           
    </s:else>
       
    </h2>
       
    <s:form action="Store" >
           
    <s:textfield name="book.isbn" label="ISBN" />
           
    <s:textfield name="book.title" label="Title" />
           
    <s:textfield name="book.price" label="Price" />
           
    <s:submit />
       
    </s:form>
    </body>
    </html>
    清單6 WebContent/Book/Edit.jsp

    如果book為null,則表明該頁面用于添加書籍,反之則為編輯頁面。

    為了方便大家運(yùn)行示例,我把web.xml的代碼也貼出來,如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" 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>Struts 2 Fileupload</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-list>

    </web-app>
    清單7 WebContent/WEB-INF/web.xml

    大功告成,下面發(fā)布運(yùn)行應(yīng)用程序,在瀏覽器中鍵入:http://localhost:8080/Struts2_CRUD/Book/List.action,出現(xiàn)如下圖所示頁面:


    清單8 列表頁面

    點(diǎn)擊“Add Book”,出現(xiàn)如下圖所示頁面:


    清單9 添加書籍頁面

    后退回到列表頁面,點(diǎn)擊“Edit”,出現(xiàn)如下圖所示頁面:


    清單10 編輯書籍頁面

    總結(jié)

    本文只是粗略地了介紹Struts 2的CRUD實(shí)現(xiàn)方法,所以有很多功能沒有實(shí)現(xiàn),如國際化和數(shù)據(jù)校驗(yàn)等。大家可以在上面例子的基礎(chǔ)將其完善,當(dāng)作練習(xí)也不錯(cuò)。如果過程中有不明白之處,可以參考我早前的文章或給我發(fā)E-Mail:max.m.yuan@gmail.com

    posted on 2007-04-13 01:37 Max 閱讀(44900) 評(píng)論(74)  編輯  收藏 所屬分類: Struts 2.0系列

    評(píng)論:
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-13 03:45 | 山風(fēng)小子
    一直關(guān)注著您的這一系列教程,辛苦了 :)  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-13 10:40 | 藍(lán)色天空的囚徒
    辛苦,辛苦!!!  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-13 12:21 | Long
    CRUD - Create, Retrieve, Update, and Delete ?
    雖然沒有必要為這些字眼來討論什么  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-13 22:47 | Max
    @Long
    謝謝,你的提醒。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-14 18:54 | furong
    MAX
    很感謝你這一系列的文章
    不知道能不能傳個(gè)關(guān)于struts2.0中樹控件運(yùn)用的例子?
    非常感謝  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-15 12:10 | hushsky
    MAX你好,謝謝你的教程,我按照你的這個(gè)例子寫了一個(gè)可以正常運(yùn)行,但是我加入對(duì)book.isbn的requiredstring校驗(yàn)(在BookAction包下加入BookAction-validation.xml,主要部分如下:)
    <validators>
    <field name="book.isbn">
    <field-validator type="requiredstring">
    <message> The id is requiredstring!!</message>
    </field-validator>
    </field>
    </validators>
    另將struts.xml中Store.action修改為
    <action name="Store" class="..." method="store">
    <result type="redirect">List.action</result>
    <result name="input">edit.jsp</result>

    在edit.jsp中可以正常對(duì)isbn校驗(yàn)
    但是由于設(shè)置的是對(duì)BookAction校驗(yàn),因此在執(zhí)行List.action時(shí)也會(huì)進(jìn)行檢驗(yàn)并返回"input”,導(dǎo)致無法運(yùn)行BookAction.list()方法
    這種情況應(yīng)該怎么進(jìn)行校驗(yàn),請(qǐng)指教,不勝感激
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-15 14:34 | Max
    最簡單的方法就是將你的BookAction-validation.xml文件改名為“BookAction-Store-validation.xml”。這樣validation的配置只對(duì)Store起作用。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-15 19:16 | hushsky
    @Max
    收到,十分感謝  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-16 14:48 | 千山鳥飛絕
    @Max
    請(qǐng)問“BookAction-Store-validation.xml”必須這樣寫嗎?為什么需要這樣寫呢?

    還有請(qǐng)問strust.xml必須寫在根目錄下嗎?
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-16 14:53 | hushsky
    MAX你好,不好意思又麻煩你
    本例中,我對(duì)book.isbn進(jìn)行rquiredstring校驗(yàn),一切正常,但是我在“BookAction-Store-validation.xml”文件中的的<field-validator >加入short-circuit屬性實(shí)現(xiàn)短路校驗(yàn)(我從webwork里看的,不知道struts2.0里是否可行)。
    代碼如下:<field-validator type="requiredstring" short-circuit="true">
    之后,程序可以運(yùn)行,但是校驗(yàn)框架就不起作用了,即便在Edit.jsp里不輸入isbn仍可以提交

    能請(qǐng)教一下原因嗎?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-16 19:19 | crayz
    感謝,你的struts2系列文章
    我是新手,這個(gè)例子我調(diào)試成功了
    但我發(fā)現(xiàn)這個(gè)。不能輸入中文。一出來就是亂碼
    我查了查資料。自己加了個(gè)spring 里包含的一個(gè)filter 解決了encoding
    問題,添加是沒問題了,但是編輯仍然有問題。一點(diǎn)就是空白
    再添上去就是。新添加非。編輯了。不知道如果解決
    可能我問的太初級(jí)。可struts2資源實(shí)在有限 沒辦法了麻煩你了
    或者能提供些編碼方面的參考資料呢。歇息  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-16 23:41 | Max
    @千山鳥飛絕
    1、請(qǐng)參考我的《在Struts 2.0中實(shí)現(xiàn)表單數(shù)據(jù)校驗(yàn)(Validation)》中“配置文件查找順序”
    2、不是,你可以通過以下設(shè)置改變struts.xml位置:
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>struts-default.xml,struts-plugin.xml,config/struts.xml</param-value>
    </init-param>
    </filter>  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-17 10:02 | Max
    @hushsky
    加入<field-validator type="requiredstring" short-circuit="true"> 之后,運(yùn)行,例子會(huì)出現(xiàn)
    org.xml.sax.SAXParseException: Attribute "short-circuit" must be declared for element type "field-validator".
    但是,按照DTD的定義,short-ciruit是合法的屬性。可能是Struts 2的BUG。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-17 10:07 | Max
    @crayz
    亂碼問題不是三言兩語能夠說得清楚的,因?yàn)檫@跟你的JVM區(qū)域(locale)、頁面編碼和IE的設(shè)置都有關(guān)。你可以GOOGLE一下,應(yīng)該有很多不錯(cuò)的文章。
    通常的做法是盡量將所有編碼類型都認(rèn)為utf-8。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-17 10:59 | hermit
    Max在線么?validate驗(yàn)證如何使一個(gè).xml文件的驗(yàn)證只對(duì)action的一個(gè)方法有效?就是說我一個(gè)action有CRUD方法,我如何讓在刪除和查詢時(shí)跳過驗(yàn)證?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-17 19:04 | Max
    @hermit
    請(qǐng)參考上面的評(píng)論  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-18 10:18 | hermit
    謝謝,你指的是“BookAction-Store-validation.xml”對(duì)么?我昨天看到了。但是還是沒有配置出來,后來我把Store改成了action訪問的全路徑(action!方法名)就可以了。但是還有個(gè)問題就是,增刪改我想讓他返回不同的頁面。昨天調(diào)了一天。沒搞定!好像這個(gè)1.x的版本也是有這個(gè)問題。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-19 01:56 | Z
    你好,我在調(diào)試你的這個(gè)例子時(shí),為什么從struts.xml的result里跳到

    List.action時(shí)會(huì)出現(xiàn)
    The requested resource (/test/Book/List.action) is not available.
    錯(cuò)誤,

    而直接用http://localhost:8080/test/Book/List.action訪問時(shí)卻可以呢

    麻煩解釋一下,謝謝  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-24 16:10 | ddd
    很好的文章。。。謝謝。。
    我這2天也才知道Struts2.0(汗),馬上看了看。。
    LZ的教程非常有幫組。。

    另外, 我對(duì)apache struts官方網(wǎng)上的教程也作了一次。。。
    http://struts.apache.org/2.x/docs/tutorials.html
    那個(gè)Struts 2 + Spring 2 + JPA + AJAX 里提到的CRUD,
    與LZ介紹的方法一致,不過,偶連Spring都沒用過,所以這2天
    就看了Spring的一些文章, 才有點(diǎn)明白了。。開始。。。

    不過,對(duì)于web.xml中關(guān)于encoding的設(shè)置,還是有點(diǎn)迷惑。。
    spring的filter沒搞定, 不知道使用自己寫的方法是否可行。。
    自己定義servletFilter類,web.xml中記述servletFilter, <init-param>
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-25 09:12 | Max
    @Z
    應(yīng)該是路徑配錯(cuò)了。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-25 09:13 | Max
    @ddd
    可能要具體問題,具體分析。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-04-26 09:15 | 123
    為什么不用中文的做例子?
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-05-08 10:11 | S
    Edit雖然能夠讀取數(shù)據(jù),但是點(diǎn)submit就會(huì)“添加”新數(shù)據(jù),而不是對(duì)原數(shù)據(jù)進(jìn)行修改。。。。
    麻煩max看一下  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-05-08 23:19 | Max
    這是因?yàn)槟愀牧薸sbn,我是用isbn作為數(shù)據(jù)的索引。理論上isbn是不可以修改的。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-05-15 18:41 | Niuzai
    好棒啊...高手...謝謝你了謝謝大家...  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-05-25 14:14 | bruy
    請(qǐng)問Max,如果我一次要增加多條Book,該怎么做呢?
    這在開發(fā)中很常見,不是一條條的去點(diǎn)添加按鈕,而是在頁面上添加多行后,一次提交,請(qǐng)問這個(gè)應(yīng)該怎么實(shí)現(xiàn)呢?  回復(fù)  更多評(píng)論
      
    # attempt to create saveOrUpdate event with null entity 2007-06-11 18:02 | sapphire
    這是什么錯(cuò)誤?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-08-11 10:37 | liy
    MAX大哥,能不能發(fā)個(gè)源碼給我,我后面做你這上面的例子都會(huì)有錯(cuò).麻煩你了.
    我的郵箱是followmephoe@yahoo.com.cn  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-08-13 19:59 | louleigh
    MAX
    大哥。
    我看你的源碼..點(diǎn)remove button的時(shí)候應(yīng)該執(zhí)行的是全部操作.
    為什么我的是null pointer exception..
    我跟蹤發(fā)現(xiàn)..
    this.getisbns()沒有獲取到值.請(qǐng)問為什么  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-08-14 09:40 | sjtde
    MAX,如果在這上面加上 token 該如何加呢?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-08-20 23:56 | 羅文飛
    book是建在那個(gè)文件下啊/  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-08-31 15:37 | tf
    我按照上面的代碼輸入運(yùn)行怎么出現(xiàn)這個(gè)錯(cuò)誤呢?
    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    file:/C:/lomboz/eclipse/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/Struts2_CRUD/WEB-INF/classes/struts.xml:2:8
    com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFile(XmlConfigurationProvider.java:678)
    com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:117)
    com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:87)
    com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:46)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:218)


    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.


    --------------------------------------------------------------------------------
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-09-12 15:54 | tigershi10
    max你好
    我想問一下
    <td><s:checkbox name="isbns" value="isbn"/></td>
    <td><input type="checkbox" name="isbns" value='<s:property value="isbn" />' /></td>
    這2條語句為什么上面那面就不行  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-10-09 16:36 | buddha
    @Max
    加入<field-validator type="requiredstring" short-circuit="true"> 之后,運(yùn)行,例子會(huì)出現(xiàn)
    org.xml.sax.SAXParseException: Attribute "short-circuit" must be declared for element type "field-validator".
    但是,按照DTD的定義,short-ciruit是合法的屬性。可能是Struts 2的BUG。

    我也碰到這個(gè)問題,真不敢相信,struts2竟會(huì)出這種低級(jí)問題。
    請(qǐng)問max兄有沒有查過struts的bug庫?或這類問題的討論?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2007-10-10 10:39 | Eric


    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    No result defined for action tutorial.action.BookAction and result input - action - file:/E:/JavaProject/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/DBStruts2/WEB-INF/classes/struts.xml:17:80
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    com.opensymphony.xwork2.interceptor. com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    org.apache.struts2.impl.StrutsActionProxy.execute

      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-10-22 15:46 | xjxy
    @buddha
    我也遇到相同的問題,但是google一下說在xml中設(shè)置為<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd" >可解決問題,試了一下,使用short-circuit是不會(huì)報(bào)錯(cuò)了,但是完全不起作用,跟沒使用short-circuit一樣,那位有更好的解決方法?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2007-11-05 13:49 | cowboy
    想請(qǐng)教一個(gè)小問題:
    為什么我把 List.jsp 頁面里的“<input type="checkbox" name="isbns" value='<s:property value="isbn" />' />”
    改為:“<s:checkbox type="checkbox" name="isbns" value='<s:property value="isbn" />' />”

    選擇一個(gè)isbn后按Remove按鈕就會(huì)出錯(cuò):
    No result defined for action com.struts2.action.UserManagerAction and result input
    這樣的錯(cuò)誤。
    如果不改就沒有錯(cuò)誤,這是為什么。
    還有,struts2.0里的“checkbox”標(biāo)簽跟html里的“input type="checkbox"”有什么區(qū)別?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-02-03 11:57 | 大漠落日
    @cowboy
    “<s:checkbox type="checkbox" name="isbns" value='<s:property value="isbn" />' />”
    --》“<s:checkbox name="isbns" value='<s:property value="isbn" />' />”
    這樣試試。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-02-21 09:41 | solong1980
    我實(shí)在忍不住了,對(duì)樓主的贊美猶如滔滔江水,連綿不絕  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-02-27 17:30 | tarzan
    好人啊,對(duì)樓主無限敬佩中.........  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2008-02-29 23:23 | Nick
    樓主,我照你的代碼寫了。但list.jsp沒有數(shù)據(jù),iterator沒有循環(huán)。怎么回事啊?
    謝謝。。。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2008-03-01 09:00 | Song
    LZ,我按上面代碼寫的。怎么沒有先調(diào)用list()啊,頁面沒有出現(xiàn)數(shù)據(jù)。。。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-03-01 11:43 | labeille
    @Nick / Song
    去掉驗(yàn)證validate() 就可以了。。。 :-)  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-03-11 13:57 | lastsweetop
    程序需要做些小修改哦
    因?yàn)樾薷膇sbn的話 原來的沒刪除 又出現(xiàn)個(gè)新的

    在dao中存放一個(gè)靜態(tài)isbn存放要修改的isbn就可以了

    呵呵 總之 很不錯(cuò) 感謝了  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-03-11 13:58 | lastsweetop
    DEBUG 2008-03-11 13:56:59.571 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/scripting-events.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-03-11 13:56:59.586 [freemark] (): Compiling FreeMarker template template/simple/scripting-events.ftl[zh_CN,UTF-8,parsed] from jar:file:/F:/tomcat/apache-tomcat-5.5.23/webapps/struts1/WEB-INF/lib/struts2-core-2.0.11.1.jar!/template/simple/scripting-events.ftl
    DEBUG 2008-03-11 13:56:59.586 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/common-attributes.ftl[zh_CN,UTF-8,parsed] ]

    每次加載或刷新頁面都會(huì)出現(xiàn)這樣的debug 請(qǐng)問又什么好的辦法解決。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2008-03-19 15:35 | king
    真正的界面不會(huì)那么簡單,我想問一下,如果我想彈出一個(gè)窗口來做增加和修改操作,應(yīng)該怎么做?  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-04-26 17:19 | helen
    寫的好精彩啊 ,看懂了,但是 我用的maven ,mvn jetty:run ,后運(yùn)行http://localhost:8080/Struts2_CRUD/Book/List.action,頁面不顯示,后臺(tái) 報(bào)錯(cuò),請(qǐng)問是什么原因呢 ?是 web.xml我沒改,strut2和maven配置不同么?不懂啊 。。。

    Exception in thread "btpool0-1" java.lang.Error: Untranslated exception
    at sun.nio.ch.Net.translateToSocketException(Net.java:65)
    at sun.nio.ch.SocketAdaptor.close(SocketAdaptor.java:354)
    at org.mortbay.io.nio.ChannelEndPoint.close(ChannelEndPoint.java:100)
    at org.mortbay.jetty.nio.SelectChannelConnector$SelectChannelEndPoint.cl
    ose(SelectChannelConnector.java:716)
    at org.mortbay.jetty.nio.HttpChannelEndPoint.close(HttpChannelEndPoint.j
    ava:329)
    at org.mortbay.jetty.nio.HttpChannelEndPoint$IdleTask.expire(HttpChannel
    EndPoint.java:369)
    at org.mortbay.jetty.nio.SelectChannelConnector$SelectSet.accept(SelectC
    hannelConnector.java:458)
    at org.mortbay.jetty.nio.SelectChannelConnector.accept(SelectChannelConn
    ector.java:175)
    at org.mortbay.jetty.AbstractConnector$Acceptor.run(AbstractConnector.ja
    va:630)
    at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool
    .java:475)
    Caused by: java.io.IOException: An operation was attempted on something that is
    not a socket
    at sun.nio.ch.SocketDispatcher.close0(Native Method)
    at sun.nio.ch.SocketDispatcher.preClose(SocketDispatcher.java:44)
    at sun.nio.ch.SocketChannelImpl.implCloseSelectableChannel(SocketChannel
    Impl.java:684)
    at java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel(Abst
    ractSelectableChannel.java:201)
    at java.nio.channels.spi.AbstractInterruptibleChannel.close(AbstractInte
    rruptibleChannel.java:97)
    at sun.nio.ch.SocketAdaptor.close(SocketAdaptor.java:352)
    ... 8 more  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2008-04-30 19:13 | jackey
    @大漠落日
    這樣設(shè)置不會(huì)報(bào)錯(cuò),但進(jìn)行刪除操作時(shí)不能真正進(jìn)行。值已經(jīng)變?yōu)閠rue/false
      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-05-12 10:42 | tt
    好人啊,對(duì)樓主無限敬佩中.........   回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-05-15 17:32 | lrm
    謝謝!  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-06-17 11:24 | hover
    @Max
    樓主,我發(fā)現(xiàn)這個(gè)例子不能實(shí)現(xiàn)連續(xù)Add Book,就是說我第一次Add成功了,但接著Add時(shí)路徑就變了,(因?yàn)槲沂前裫sp放在一個(gè)文件夾中的,這樣利于管理)  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-06-17 11:40 | hover
    @Max
    問題解決了,原來是因?yàn)槲野裯amespace="/operate"去掉,而把<result>List.jsp</result>改成了<result>/operate/List.jsp</result>,把它改成樓主的方法就可以了。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-07-04 16:10 | yellow race
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-07-29 15:31 | se
    @louleigh
    @louleigh
    看下Book.java得構(gòu)造函數(shù)public Book(){}有沒漏寫   回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-07-30 10:46 | dxm
    @xjxy
    我按你說的這樣寫了,結(jié)果可以實(shí)現(xiàn)啊。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2008-08-07 14:19 | matrix
    每篇文章都是精品,頂。期待MAX兄更多好文章。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-09-04 10:21 | ren
    @tf
    Book類中少了構(gòu)造函數(shù)
    public Book() {
    }  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-09-04 11:10 | 非主流@bin
    max朋友你好,我也是最近開始研究struts2的。覺得這個(gè)框架很經(jīng)濟(jì)。配置很完善。目前我在一一的看你的教程,很好很強(qiáng)大。希望你可以給我發(fā)個(gè)這些教程的src源代碼好嗎?
    lanisha00006@163.com
    不勝感激~~~  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-09-05 14:35 | walkes
    DEBUG 2008-09-05 14:33:01.406 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/form.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-09-05 14:33:01.421 [freemark] (): Compiling FreeMarker template template/simple/form.ftl[zh_CN,UTF-8,parsed] from jar:file:/D:/workspace/struts2_helloworld/WebRoot/WEB-INF/lib/struts2-core-2.0.11.2.jar!/template/simple/form.ftl
    DEBUG 2008-09-05 14:33:02.250 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/submit.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-09-05 14:33:02.265 [freemark] (): Compiling FreeMarker template template/simple/submit.ftl[zh_CN,UTF-8,parsed] from jar:file:/D:/workspace/struts2_helloworld/WebRoot/WEB-INF/lib/struts2-core-2.0.11.2.jar!/template/simple/submit.ftl
    DEBUG 2008-09-05 14:33:02.515 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/scripting-events.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-09-05 14:33:02.515 [freemark] (): Compiling FreeMarker template template/simple/scripting-events.ftl[zh_CN,UTF-8,parsed] from jar:file:/D:/workspace/struts2_helloworld/WebRoot/WEB-INF/lib/struts2-core-2.0.11.2.jar!/template/simple/scripting-events.ftl
    DEBUG 2008-09-05 14:33:02.531 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/common-attributes.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-09-05 14:33:02.546 [freemark] (): Compiling FreeMarker template template/simple/common-attributes.ftl[zh_CN,UTF-8,parsed] from jar:file:/D:/workspace/struts2_helloworld/WebRoot/WEB-INF/lib/struts2-core-2.0.11.2.jar!/template/simple/common-attributes.ftl
    DEBUG 2008-09-05 14:33:02.546 [freemark] (): Could not find template in cache, creating new one; id=[template/simple/form-close.ftl[zh_CN,UTF-8,parsed] ]
    DEBUG 2008-09-05 14:33:02.546 [freemark] (): Compiling FreeMarker template template/simple/form-close.ftl[zh_CN,UTF-8,parsed] from jar:file:/D:/workspace/struts2_helloworld/WebRoot/WEB-INF/lib/struts2-core-2.0.11.2.jar!/template/simple/form-close.ftl

    好多次都有這個(gè)DUBUG信息,不過沒有看明白什么意思,max老大知道解釋下,另外方便的話給我發(fā)一份這個(gè)系列教程的源代碼,謝謝。
    mail to: walkes@163.com  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-11-19 14:07 | lrl
    相見恨晚啊。。。max大哥  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2008-11-27 11:09 | struts2
    有后續(xù)的文章么?期待啊1  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2009-01-15 11:31 | min
    徹頭徹尾的感謝,看了你的“在Struts 2中實(shí)現(xiàn)CRUD”,讓我在struts2方面有了大的突破。
    以后一定常來光顧 新年快樂!  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2009-02-12 12:22 | adming
    to All :
    關(guān)于<s:checkbox/>和<input type="checkbox"/>的不同:
    <s:checkbox />的fieldValue屬性才相當(dāng)于<input type="checkbox"/>的value屬性,可以通過查看頁面的源代碼得知  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2009-04-28 15:45 | scorris
    有個(gè)小小問題,樓主以book對(duì)象是否為空,判斷是新增還是修改,這個(gè)方法不可行。原因是:
    在“新增頁面”,假設(shè)使用驗(yàn)證框架,驗(yàn)證不通過就會(huì)返回“新增頁面”,這時(shí)候book對(duì)象已經(jīng)不為空了,原來的“新增頁面”就會(huì)變成“修改頁面”  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2009-10-28 21:31 | 2008iava
    很有用的知識(shí)。。謝謝了。動(dòng)手去試試。。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2010-01-21 14:19 |
    樓主很容易被累死  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2010-01-22 12:22 | liuxiao
    Max兄:您好!這里我有些疑問,還望不吝賜教
    程序的執(zhí)行過程是首先通過List.action調(diào)用tutorial.action.BookAction,
    這時(shí)會(huì)對(duì)通過BookDao dao = BookDao.getInstance()進(jìn)行dao的實(shí)例化,實(shí)例化之后會(huì)在對(duì)象dao中形成一個(gè)ConcurrentMap類型的data對(duì)象。這個(gè)對(duì)象中包括初始化的那些書籍。程序到這一步?jīng)]什么問題,但是當(dāng)點(diǎn)擊edit、add book、delete之后進(jìn)入相應(yīng)的edit.jsp頁面或action處理之后又通過List.action跳轉(zhuǎn)到List.jsp頁面,這時(shí)在每一步跳轉(zhuǎn)中tutorial.action.BookAction都會(huì)通過BookDao dao = BookDao.getInstance()進(jìn)行初始化,那么其中dao.data這個(gè)對(duì)象不是每次都會(huì)被重新賦值了嗎?但是為什么沒有發(fā)生這種情況呢?

      回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2010-03-11 12:05 | j
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2011-05-15 15:01 | 肖碩
    你寫的真是太好了,好神奇啊  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2012-01-30 10:40 | Bruce
    @Z
    Struts.xml中的配置有可能沒寫對(duì)
    是<result type="redirect">List.action</result>
    而不是<result>List.action</result>  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD[未登錄] 2012-02-03 14:26 | Bruce
    照例子實(shí)踐了,非常不錯(cuò)。感謝  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2012-06-07 23:36 | ying
    @liuxiao
    BookDao是單例。  回復(fù)  更多評(píng)論
      
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2014-08-13 09:57 | witleo
    # re: 在Struts 2中實(shí)現(xiàn)CRUD 2014-08-13 10:00 | @。@
    @witleo
    你知道什么了  回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 毛片无码免费无码播放 | 亚洲精品成人久久| 国产免费一区二区视频| 亚洲精品蜜桃久久久久久| 999zyz**站免费毛片| 亚洲国产另类久久久精品| 免费一级毛片在线播放视频| 亚洲va国产va天堂va久久| 免费成人高清在线视频| 亚洲人成电影在线天堂| 91精品视频在线免费观看| 亚洲精品国产福利在线观看| 97人妻无码一区二区精品免费| 亚洲一区二区三区在线| 国产精品视频永久免费播放| 亚洲永久网址在线观看| 日本一道综合久久aⅴ免费| 免费无码国产在线观国内自拍中文字幕 | 久久国产乱子免费精品| 99久久精品国产亚洲| 国产精彩免费视频| 亚洲一级特黄特黄的大片| 免费的一级黄色片| 深夜A级毛片视频免费| 国产亚洲一区区二区在线 | 久久精品国产精品亚洲| 91免费国产视频| 亚洲永久永久永久永久永久精品| a拍拍男女免费看全片| 亚洲色偷偷综合亚洲AV伊人蜜桃| 国产免费牲交视频| 9久久免费国产精品特黄| 亚洲一区二区电影| 成人无码区免费视频观看| 羞羞视频免费网站入口| 亚洲综合图色40p| 5555在线播放免费播放| 久久乐国产综合亚洲精品| 免费a级毛片无码a∨性按摩| 国产在线观a免费观看| 亚洲成年人免费网站|