📄 pettypeservlet.java
字号:
package Control_PetType;
import Model_PetType.PetType;
import Model_PetType.PetTypeBean;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
public class PetTypeServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
request.setCharacterEncoding("GB2312");
this.doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("GB2312");
String action=request.getParameter("action");
if(action!=null)
{
if (action.equals("add"))
{
PetType pt=new PetType();
pt.setPetTypeId(request.getParameter("TypeID"));
pt.setPetTypeName(request.getParameter("TypeName"));
PetTypeBean ptb=new PetTypeBean();
boolean b=ptb.InsertPetType(pt);
try
{
if(b)
{
response.sendRedirect("PetType.jsp");
}
else
{
response.sendRedirect("Error.jsp");
}
}
catch(Exception e)
{
out.println("error"+e.getMessage());
}
}
else if (action.equals("update"))
{
PetType pt=new PetType();
pt.setPetTypeId(request.getParameter("TypeID"));
pt.setPetTypeName(request.getParameter("TypeName"));
PetTypeBean ptb=new PetTypeBean();
String b=ptb.UpdatePetType(pt);
try
{
if(b.equals("修改成功"))
{
response.sendRedirect("PetType.jsp");
}
else
{
response.sendRedirect("Error.jsp");
}
}
catch(Exception e)
{
out.println("error"+e.getMessage());
}
}
else if (action.equals("delete"))
{
PetType pt=new PetType();
pt.setPetTypeId(request.getParameter("TypeID"));
PetTypeBean ptb=new PetTypeBean();
String b=ptb.DeletePetType(pt.getPetTypeId());
try
{
if(b.equals("删除成功"))
{
response.sendRedirect("PetType.jsp");
}
else
{
response.sendRedirect("Error.jsp");
}
}
catch(Exception e)
{
out.println("error"+e.getMessage());
}
}
}
out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -