searchaction.java
来自「应用了最基本的struts框架开发」· Java 代码 · 共 34 行
JAVA
34 行
package addressbook.actions;import addressbook.Constants;import addressbook.forms.*;import addressbook.model.*;import org.apache.struts.action.*;import javax.servlet.http.*;public class SearchAction extends Action { public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { /**@todo: complete the business logic here, this is just a skeleton.*/ SearchForm searchForm = (SearchForm) actionForm; String name=searchForm.getName(); String phone=searchForm.getPhone(); String address=searchForm.getAddress(); String strSql=new String("select * from book where "); if(!name.equals("")) strSql=strSql+"name LIKE '"+name+"%' AND"; if(!phone.equals("")) strSql=strSql+"phone LIKE '"+phone+"%' AND"; if(!address.equals("")) strSql=strSql+"address LIKE '"+address+"%'"; else strSql=strSql.substring(0,strSql.length()-3); strSql=strSql+" order by ID"; HttpSession session=httpServletRequest.getSession(); session.setAttribute("session",strSql); //System.out.println(session.getAttribute("session")); return (actionMapping.findForward("view")); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?