📄 isexistempname.java
字号:
package com.liu.ems.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.liu.ems.hibernate.EmployeesDAO;
public class isExistEmpName extends HttpServlet {
/**
* Constructor of the object.
*/
public isExistEmpName() {
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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// request.setCharacterEncoding("GBK");
// response.setCharacterEncoding("GBK");
//1.取得参数
String str=request.getParameter("empname");
String empname=new String(str.getBytes("GBK"));
System.out.print("要检查的职员姓名:"+empname);
//2.检查职员姓名是否存在
boolean falg=false;
List list=new EmployeesDAO().findByEmpName(empname);
if(list==null || list.size()<=0){
falg=true;
}else{
falg=false;
}
System.out.print(falg);
System.out.print(list.size());
//3.发送响应值
out.print(falg);
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方法
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 + -