⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stumess.java

📁 用Java编写的简易的学生信息管理系统,有涉及到java web等
💻 JAVA
字号:
package com.servlet;

import java.io.IOException;
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.bean.Student;
import com.impl.Studentimpl;

public class Stumess extends HttpServlet {

	/**
	 * 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 {

		doPost(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 {
		//从页面中获得参数 n为标志,页面没有n时默认为添加 
		String absPath=request.getSession().getServletContext().getRealPath("") ;

		String n = request.getParameter("n");
		String nid = request.getParameter("sStuNo");

		if (n == null || n.trim().equals("")) {
			n = "stumes";
		}
		if (n.equals("add")) {
			request.getRequestDispatcher("/show/addstudent.jsp").forward(request,
					response);
		}else 
		// 插入一个学生的信息;
		if (n.equals("insert")) {
			Studentimpl dao = new Studentimpl(absPath);
			Student student = new Student();
			if(dao.getSno(request.getParameter("sStuNo"))){
				response.getOutputStream().println("<script lanager='javascript'>alert('学号"+request.getParameter("sStuNo")+"已经存在,添加失败. ');history.go(-1);</script>");
				return ;
			}
			String[] str=request.getParameter("brith").split("-");
			student.setYear(Integer.parseInt(str[0]));
			student.setMonth(Integer.parseInt(str[1]));
			student.setDay(Integer.parseInt(str[2]));
			student.setSDepartment(request.getParameter("sDepartment"));
			student.setSSex(request.getParameter("sSex"));
//			System.out.println(request.getParameter("sSex"));
			student.setSName(request.getParameter("sName"));
			student.setSStuNo(request.getParameter("sStuNo"));
			student.setSSpecialty(request.getParameter("sSpecialty"));
			student.setFScore1(Float
					.parseFloat(request.getParameter("fScore1")));
			student.setFScore2(Float
					.parseFloat(request.getParameter("fScore2")));
			student.setFScore3(Float
					.parseFloat(request.getParameter("fScore3")));
			student.setFScore4(Float
					.parseFloat(request.getParameter("fScore4")));
			if(dao.toinsert(student)){
				response.getOutputStream().println("<script lanager='javascript'>alert('学号"+request.getParameter("sStuNo")+",添加成功. ');location.href='stumess';</script>");
				return ;
			}else{
				response.getOutputStream().println("<script lanager='javascript'>alert('未知原因,添加失败,请检查输入项. ');history.go(-1);</script>");
				return ;
			}
		}else
		// 删除某个学生的信息
		if (n.equals("delete")) {
			Studentimpl dao=new Studentimpl(absPath);
			
			if(dao.delete(nid)){
				response.getOutputStream().println("<script lanager='javascript'>alert('学号"+nid+",删除成功. ');location.href='stumess';</script>");
				return ;
			}else{
				response.getOutputStream().println("<script lanager='javascript'>alert('未知原因,学号"+nid+",删除失败. ');location.href='stumess';</script>");
				return ;
			}
		}else
		// 求每个fScorei的平均值
		if (n.equals("everyavg")) {
			Studentimpl dao=new Studentimpl(absPath);
			List list=dao.getAvg();
			List stulist=dao.getStudentInfo(null, null);
			request.setAttribute("avglist", list);
			request.setAttribute("list", stulist);
			request.getRequestDispatcher("/show/showstudnet.jsp").forward(
					request, response);
		}else
		// 某个学生的平均分
		if (n.equals("avg")) {
			Studentimpl dao=new Studentimpl(absPath);
			float avg=dao.getStudentAvg(nid);
			List stulist=dao.getStudentInfo(nid, null);
			
			request.setAttribute("avglist",Float.toString(avg) );
			request.setAttribute("stulist", stulist);
			request.getRequestDispatcher("/show/showstudnet.jsp").forward(
					request, response);
		}else
		//获得所有学生信息
		if (n.equals("stumes")) {
			Studentimpl dao = new Studentimpl(absPath);
			String studentNo =request.getParameter("studentNo");
			String studentName =request.getParameter("studentName");
			List list=dao.getStudentInfo(studentNo,studentName);
			System.out.println("list:"+list);
			System.out.println(list.size());
			//request.getSession().setAttribute("list", list);
			request.setAttribute("list", list);
			request.setAttribute("studentNo", studentNo);
			request.setAttribute("studentName", studentName);
			request.getRequestDispatcher("/show/showstudnet.jsp").forward(request,
					response);
		}else
		//根据学号或者姓名进行查找
		if(n.equals("search")){
			Studentimpl dao=new Studentimpl(absPath);
			String name=request.getParameter("sName");
			List list=dao.getStudentInfo(nid, name);
			request.setAttribute("list", list);
			request.getRequestDispatcher("/show/showstudnet.jsp").forward(request,
					response);
		}else
		//对某个fscorei进行排序
		if (n.equals("compositor")) {
			int i=Integer.parseInt(request.getParameter("param"));
			Studentimpl dao=new Studentimpl(absPath);
			List list=dao.compositor(i);
			request.setAttribute("list", list);
			request.setAttribute("param"+i, "↓");
			request.getRequestDispatcher("/show/showstudnet.jsp").forward(
					request, response);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -