2 shouniezhe shouniezhe 于 2014.06.07 10:41 提问

struts2中action中的方法无故被提交两次

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.hsp.book.domain.Book;
import com.hsp.book.service.BookService;
import com.hsp.paper.PageModel;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BookAction extends ActionSupport implements ModelDriven{
private HttpServletRequest request=ServletActionContext.getRequest();
private BookService bookService=new BookService();
private Book book=new Book();
private PageModel pageModel;
private int pageNo=1; //这里给pageNo一个默认值
private int pageSize=4;

public int getPageNo() {
    return pageNo;
}

public void setPageNo(int pageNo) {
    this.pageNo = pageNo;
}

public Book getBook() {
    return book;
}

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

public PageModel getPageModel() {
    return pageModel;
}

public void setPageModel(PageModel pageModel) {
    this.pageModel = pageModel;
}

public Book getModel() {
    System.out.println("haha");
    return book;
}

/*
 * 按book的id查询
 * */
public String  load(){
    //int requestId=Integer.parseInt(request.getParameter("id"));
  //  book=bookService.load(book.getId()); //值传递了一个id过
    book=bookService.load(2); //值传递了一个id过
    System.out.println("按照书的id进行查找");
    System.out.println(book.getId());
    System.out.println(book.getImage_b());
    return "desc";
}

}

struts.xml

     <action name="bookAction_*" class="com.hsp.book.web.action.BookAction" method="{1}">

         <result name="list">/jsps/book/list.jsp</result>
         <result name="desc">/jsps/book/desc.jsp</result>
     </action>
</package>

jsp的链接代码:

${book.bname}

最后的结果是action中的load()被调用两次。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!