📄 matchcheckservlet.java
字号:
package com.csu.crm.common.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import com.csu.crm.common.dao.SqlStringDAO;
import com.csu.crm.common.dao.original.CrmEmployeeDAO;
import com.csu.crm.common.vo.CrmEmployee;
/**
* 此servlet用于测试输入的字符是否和希望值匹配
*
* @author 3eCRM小组:曾东
* @since Oct 1, 2007 8:35:41 PM
* @version 1.0 创建时间:Oct 1, 2007 8:35:41 PM,初始版本
*/
public class MatchCheckServlet extends HttpServlet {
private static final Log log = LogFactory.getLog(MatchCheckServlet.class);
private SqlStringDAO sqlStringDAO;
private CrmEmployeeDAO crmEmployeeDAO;
public CrmEmployeeDAO getCrmEmployeeDAO() {
return crmEmployeeDAO;
}
public void setCrmEmployeeDAO(CrmEmployeeDAO crmEmployeeDAO) {
this.crmEmployeeDAO = crmEmployeeDAO;
}
public SqlStringDAO getSqlStringDAO() {
return sqlStringDAO;
}
public void setSqlStringDAO(SqlStringDAO sqlStringDAO) {
this.sqlStringDAO = sqlStringDAO;
}
/**
* Constructor of the object.
*/
public MatchCheckServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
response.setContentType("text/html; charset=gb2312");
String para ="org.springframework.web.struts.ContextLoaderPlugIn.CONTEXT.";
WebApplicationContext wac = (WebApplicationContext)this.getServletContext().getAttribute(para);
sqlStringDAO = (SqlStringDAO)wac.getBean("SqlStringDAO");
crmEmployeeDAO = (CrmEmployeeDAO)wac.getBean("CrmEmployeeDAO");
String vo = request.getParameter("vo");
String property1 = request.getParameter("property1");
String property2 = request.getParameter("property2");
String value1 = request.getParameter("value1");
String value2 = request.getParameter("value2");
String hql = "select tmp from " + vo + " as tmp where tmp." + property1 + "='" +value1+ "' and tmp." + property2 + "='" + value2 +"'";
log.warn("[MatchCheckServlet]---" + hql);
boolean flag = sqlStringDAO.isExisted(hql);
log.warn("[MatchCheckServlet]------" + flag);
PrintWriter out=response.getWriter();
if(flag) {
//如果存在则
out.write("existed");
//存在的话还必须 使此对象成为持久化对象
//CrmEmployee crmEmployee = (CrmEmployee)sqlStringDAO.getObject(hql);
//crmEmployeeDAO.attachClean(crmEmployee);
}else {
//如果不存在
out.write("notexisted");
}
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -