package com.aheadetp.xm.epet.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 com.aheadetp.xm.epet.biz.PetInfoBiz;
import com.aheadetp.xm.epet.biz.impl.PetInfoBizImpl;
import com.aheadetp.xm.epet.entity.PetInfo;
public class ShowBabyServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public ShowBabyServlet() {
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 {
//得到传入参数:宠物ID
String id=request.getParameter("id");
if(id==null)
{
request.setAttribute("error", "没有指定宠物编号");
request.getRequestDispatcher("/jsp/error.jsp").forward(request, response);
return ;
}
int petId=Integer.parseInt(id);
//调用Biz方法,得到宠物数据
PetInfoBiz biz=new PetInfoBizImpl();
PetInfo petInfo=biz.load(petId);
if(null==petInfo)
{
request.setAttribute("error", "没有指定编号的宠物记录");
request.getRequestDispatcher("/jsp/error.jsp").forward(request, response);
return ;
}
//将宠物数据保存到request中
request.setAttribute("item", petInfo);
//转发到petInfo.jsp
request.getRequestDispatcher("/jsp/pet/petInfo.jsp").forward(request, response);
}
/**
* 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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}