📄 findaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.tang.struts.action;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 com.tang.foruse.BookBean;
import com.tang.foruse.GetConn;
import com.tang.struts.form.FindForm;
/**
* MyEclipse Struts
* Creation date: 05-21-2008
*
* XDoclet definition:
* @struts.action path="/find" name="findForm" input="/index.jsp" scope="request" validate="true"
*/
public class FindAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String target = "failure";
FindForm findForm = (FindForm) form;// TODO Auto-generated method stub
String name = null;
String name1 = null;
try {
name = new String(findForm.getFind().getBytes("ISO-8859-1"),"UTF-8");
name1 = new String(findForm.getType().getBytes("ISO-8859-1"),"UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
findForm.setFind(name);
findForm.setType(name1);
GetConn gc = new GetConn();
Connection conn =gc.GetConnectioon();
PreparedStatement pstm = null;
ResultSet rs = null;
String findContent = findForm.getFind();
ArrayList al = new ArrayList();
String findType = findForm.getType().equals("������")?"author":"name";
try {
pstm = conn.prepareStatement("select * from books where "+findType+" like'%"+findContent+"%'");
//pstm.setString(1, findType);
//pstm.setString(2, "auth");
rs = pstm.executeQuery();
while(rs.next())
{
BookBean bean = new BookBean();
bean.setId(rs.getInt(1));
bean.setName(rs.getString(2));
bean.setPrice(rs.getDouble(4));
bean.setAuthor(rs.getString("author"));
bean.setImage(rs.getString("image"));
bean.setPublishhouse(rs.getString(10));
al.add(bean);
}
request.setAttribute("beanAl", al);
target = "success" ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward(target);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -