⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchtutorialaction.java

📁 印度高手Struts and Hibernate教程,用MyEclipse开发.书和源码In this tutorial we will show how the Web Framework Stru
💻 JAVA
字号:
package roseindia.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletContext;

import java.util.List;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import roseindia.net.plugin.HibernatePlugIn;

import roseindia.net.dao.hibernate.Tutorial;

import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Criteria;



public class SearchTutorialAction extends Action
{
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
	SearchTutorialActionForm formObj = (SearchTutorialActionForm)form;

	 System.out.println("Getting session factory");
	 /*Get the servlet context */
	 ServletContext context = request.getSession().getServletContext();
	 /*Retrieve Session Factory */
	 SessionFactory _factory = (SessionFactory)  context.getAttribute(HibernatePlugIn.SESSION_FACTORY_KEY);
	 /*Open Hibernate Session */
	 Session  session = _factory.openSession();
     //Criteria Query Example
     Criteria crit = session.createCriteria(Tutorial.class);
     crit.add(Restrictions.like("shortdesc", "%" + formObj.getKeyword() +"%")); //Like condition

	 //Fetch the result from database
	 List tutorials= crit.list();
	 request.setAttribute("searchresult",tutorials);
	 
	  /*Close session */
      session.close();
	  System.out.println("Hibernate Session Closed");
      return mapping.findForward("success");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -