寒假第十天
Posted 520520520zl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寒假第十天相关的知识,希望对你有一定的参考价值。
package com.zzw.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class AddBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String type= request.getParameter("btype"); int money=Integer.parseInt(request.getParameter("bmoney")); String date= request.getParameter("bdate"); String remark= request.getParameter("bremark"); Bill bill =new Bill(type,money,date,remark); //接口 x=new 实现类() IUserService userservice = new UserServiceImpl(); boolean result=userservice.AddBill(bill); if(!result) { request.setAttribute("message","error"); }else { request.setAttribute("message","noerror"); } request.getRequestDispatcher("add.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class DeleteBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); int id= Integer.parseInt(request.getParameter("bid")); IUserService userservice = new UserServiceImpl(); boolean result=userservice.DeleteBill(id); if(!result) { request.setAttribute("message","error"); }else { request.setAttribute("message","noerror"); } request.getRequestDispatcher("QueryAllBillServlet").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.zzw.entity.User; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class LoginServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String name= request.getParameter("uname"); String pwd= request.getParameter("upwd"); User user = new User(name,pwd); //接口 x=new 实现类() IUserService userservice = new UserServiceImpl(); boolean result=userservice.Login(user); if(!result) { request.setAttribute("message","error"); request.getRequestDispatcher("login.jsp").forward(request, response); }else { request.setAttribute("message","noerror"); request.getRequestDispatcher("index.jsp").forward(request, response); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.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.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class QueryAllBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); IUserService userservice = new UserServiceImpl(); List<Bill> bills=userservice.QueryAll(); //out对象的获取方法 PrintWriter out = response.getWriter(); request.setAttribute("bills", bills); request.getRequestDispatcher("show.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.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.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class QueryBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); //获取待查询修改人的学号 int id= Integer.parseInt(request.getParameter("bid")); IUserService userservice = new UserServiceImpl(); Bill bill=userservice.Query(id); //out对象的获取方法 PrintWriter out = response.getWriter(); out.println(bill); request.setAttribute("bill", bill); request.getRequestDispatcher("billinfo.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.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.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class QueryDateServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String date=request.getParameter("bdate"); IUserService userservice = new UserServiceImpl(); List<Bill> bills=userservice.QueryDate(date); //out对象的获取方法 PrintWriter out = response.getWriter(); request.setAttribute("bills", bills); request.getRequestDispatcher("screendate.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.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.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class QueryPartBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String type=request.getParameter("btype"); String date=request.getParameter("bdate"); System.out.println(type+date); IUserService userservice = new UserServiceImpl(); List<Bill> bills=userservice.QueryPart(type,date); //out对象的获取方法 PrintWriter out = response.getWriter(); request.setAttribute("bills", bills); request.getRequestDispatcher("screen.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.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.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class QueryTypeServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String type=request.getParameter("btype"); IUserService userservice = new UserServiceImpl(); List<Bill> bills=userservice.QueryType(type); //out对象的获取方法 PrintWriter out = response.getWriter(); request.setAttribute("bills", bills); request.getRequestDispatcher("screentype.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.zzw.entity.User; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class RegisterServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); String name= request.getParameter("uname"); String pwd= request.getParameter("upwd"); String sex= request.getParameter("usex"); User user = new User(name,pwd,sex); //接口 x=new 实现类() IUserService userservice = new UserServiceImpl(); boolean result=userservice.Register(user); if(!result) { request.setAttribute("message","error"); request.getRequestDispatcher("register.jsp").forward(request, response); }else { request.setAttribute("message","noerror"); request.getRequestDispatcher("register.jsp").forward(request, response); } } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } package com.zzw.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.zzw.entity.Bill; import com.zzw.service.IUserService; import com.zzw.service.Impl.UserServiceImpl; public class UpdateBillServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8"); //获取待修改人的学号 int id= Integer.parseInt(request.getParameter("bid")); //获取修改后的内容 String type=request.getParameter("btype"); int money= Integer.parseInt(request.getParameter("bmoney")); String date= request.getParameter("bdate"); String remark= request.getParameter("bremark"); //将修改后的内容封装到一个实体类中 Bill bill = new Bill(type,money,date,remark); IUserService userservice = new UserServiceImpl(); boolean result=userservice.UpdateBill(id,bill); if(!result) { request.setAttribute("message","error"); }else { request.setAttribute("message","noerror"); } request.getRequestDispatcher("QueryAllBillServlet").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }
家庭记账本servlet部分类容如上
以上是关于寒假第十天的主要内容,如果未能解决你的问题,请参考以下文章