package dgut.ke.servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ajaxtags.helpers.AjaxXmlBuilder;
import org.ajaxtags.servlets.BaseAjaxServlet;
import org.springframework.web.context.support.WebApplicationContextUtils;
import dgut.ke.model.Book;
import dgut.ke.service.IBookService;
@SuppressWarnings("serial")
public class BookCallOut extends BaseAjaxServlet {
private IBookService bookService;
@Override
public String getXmlContent(HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
String bookName = request.getParameter("bookName");
System.out.println("---- " + bookName);
Book book = (Book) bookService.findForObject(
"from Book as b where b.bookName=?",new Object[]{bookName});
AjaxXmlBuilder builder = new AjaxXmlBuilder()
.addItemAsCData("提示标题", "<P>关于书籍:<b>" + book.getBookNo() +"</b>的信息如下:<br/></p>");
return builder.toString();
}
@Override
public void init(ServletConfig servletConfig) throws ServletException {
// 必须在重写方法的第一行调用以下语句
super.init(servletConfig);
bookService = (IBookService) WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext())
.getBean("bookService");
}
}
posted on 2007-11-25 13:42
Ke 阅读(3011)
评论(2) 编辑 收藏 所属分类:
spring