我想問可否用Ajax取得用struts2 action從資料庫撈出來的值?
我想問可否用Ajax取得用struts2 action從資料庫撈出來的值?
因為我struts2已經與SPRING HIBERNATE整合好了
所以想說若要增加用AJAX的功能 是否可以讓AJAX取得ACTION回傳的值
而不用導頁 因為struts2 一導頁 有AJAX的頁面就全更新的
我下面的CODE是STRUTS會導回給自己 但這樣AJAX就有問題了
以下是我的CODE
------這是action的CODE--------------------------
package com.mkyong.user.action;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.FileSystemXmlApplicationContext;
//import java.awt.print.Book;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.PrintWriter;
import com.mkyong.user.bo.UserBo;
import com.mkyong.user.hibernate.Book;
import com.mkyong.user.service.BookService;
import com.mkyong.user.service.BookServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
public class UserSpringAction extends ActionSupport{
//DI via Spring
UserBo userBo;
//UserBo bookDAO; //丟給SERVICE去處理了
BookService bookService;
private String name;
private String price;
private String status; //這要給false.jsp來判斷 拿到誰的
public UserBo getUserBo() {
return userBo;
}
public void setUserBo(UserBo userBo) {
this.userBo = userBo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/* public UserBo getBookDAO() {
return bookDAO;
}
public void setBookDAO(UserBo bookDAO) {
this.bookDAO = bookDAO;
} */
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public BookService getBookService() {
return bookService;
}
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
public String execute() throws Exception {
// price = userBo.queryBook(name);
// Book book = bookDAO.getBook("yaya");
// price = book.getBookPrice();
// ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
// UserBo bookDAO = (UserBo) context.getBean("bookDAO");
// Book book = bookDAO.getBook(name); //丟給SERVICE處理
//BookService bookService =&nb