首页 > 其他分享 >5.29

5.29

时间:2023-05-29 23:35:15浏览次数:41  
标签:pageNo request getParameter import servlet response 5.29

今天Java考试

代码如下

package 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 model.PageBean;

import dao.Impl.EmpBiz;

public class PageServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
EmpBiz biz=new EmpBiz();
int pageNo=1;
int pageCount=10;
int totalPage=0;
String pageNoStr=request.getParameter("pageNo");
String pageCountStr=request.getParameter("pageCount");
String totalPageStr=request.getParameter("totalPage");
if(totalPageStr!=null){
totalPage=Integer.parseInt(totalPageStr);
}
if(pageNoStr!=null){
pageNo=Integer.parseInt(pageNoStr);

if(pageNo==0){
pageNo=1;
}else if(pageNo>totalPage || pageNo==totalPage){
pageNo=totalPage;
}
}
if(pageCountStr!=null){
pageCount=Integer.parseInt(pageCountStr);
}

PageBean pageBean=biz.listEmps(pageNo, pageCount);
request.setAttribute("list", pageBean);
request.getRequestDispatcher("admin/userAllInfo.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
doGet(request,response);
}
}

 

package servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.Impl.CourseServiceImpl;

import dao.Impl.CourseDaoImpl;

import model.Course;
import model.Student;
import model.User;

public class ServletaddCourse extends HttpServlet{

private Course course;
private ServletFindAllCos servletFindAllCos=new ServletFindAllCos();
private CourseServiceImpl courseServiceImpl=new CourseServiceImpl();

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String courseName = request.getParameter("courseName");
int courseCredit = Integer.parseInt(request.getParameter("courseCredit"));
int courseHours = Integer.parseInt(request.getParameter("courseHours"));
String courseTea = request.getParameter("courseTea");
String coDate = request.getParameter("courseDate");
Date courseDate=null;
try {
courseDate = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("courseDate"));
} catch (ParseException e) {

e.printStackTrace();
}

// System.out.println(courseDate);
course=new Course(courseName,courseCredit,courseHours,courseTea,courseDate);
//new Course( courseName, courseCredit, courseHours,
// courseTea, courseDate);
//验证是否存在该教师课程
Course cos=courseServiceImpl.selectOneCos(course);
if(cos==null){
int rs=courseServiceImpl.addCos(course,coDate);
if(rs>0){
request.setAttribute("msg", "添加成功!!");
servletFindAllCos.doGet(request, response);
// request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);
}else{
request.setAttribute("msg", "添加失败!!");
request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);
}
}else{
request.setAttribute("msg", "该课程已录入,请重新输入!!");
request.getRequestDispatcher("admin/addCourse.jsp").forward(request, response);
}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

标签:pageNo,request,getParameter,import,servlet,response,5.29
From: https://www.cnblogs.com/wangzelin/p/17442007.html

相关文章

  • 2023.5.29Linux系统压缩打包
    02.Linux系统压缩打包1.zip压缩工具2.TAR压缩工具3.TAR实践案例windows下我们接触最多的压缩文件就是rar格式,但linux有自己所特有的压缩工具如果希望windiows和linux互相能使用的压缩工具,建议.zip格式压缩的好处主要有节省磁盘空间占用率节省网络传输带宽消耗网络传输更......
  • 5.29每日总结
    今天上课做了这学期的测试,虽然长时间没有写html及前端的东西,但是还是比较顺利的完成了;林另外下面是我们团队队员总结团队内部的问题:在项目开发的过程中,我们团队存在诸多潜在问题。经过改进的用户界面仍然不够友好。由于开发团队没有专业的界面美工设计人员,以及没有足够的用......
  • 2023.5.29每日总结
    publicAllMethods()throwsException{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost:3306/rjgc?useSSL=false&useUnicode=true&characterEncoding=utf8";Stringusername="......
  • 每日总结-23.5.29
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"&g......
  • 5.29 数学模拟赛 1
    A.之前写过题解,不说了。B.N钱买N鸡,要求O(n)。思路还是和之前一样,但是提供一种新写法:#include<bits/stdc++.h>#definelllonglongusingnamespacestd;lln;intans[29]={1,0,0,0,1,0,0,1,1,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1};i......
  • 《安富莱嵌入式周报》第267期:2022.05.23--2022.05.29
    ​​​​  本周更新了两期视频:BSP视频教程第16期:DMA双缓冲实现32路脉冲并行同步控制(2022-05-26)​​​https://www.armbbs.cn/forum.php?mod=viewthread&tid=112560​​ ......
  • MDK5.29,5.30,5.31,5.32,5.33, 5.34,5.35, 5.36, 5.37和各种pack软件包镜像下载(2022-05-04)
    MDK5.29,5.30,5.31,5.32,5.33,5.34,5.35,5.36,5.37和各种pack软件包镜像下载(2022-05-04) MDK软件:​​​mdk454.exe​​​(491.23MB)​​​mdk474.exe​​​(576.82MB)​​​......