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

📄 selectservlet.java

📁 学习 java 做 的一些 小 试验。。。。。。。可以
💻 JAVA
字号:
package com.wczy.servlet;

import java.io.IOException;
//import java.io.PrintWriter;
import java.util.ArrayList;

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

import com.wczy.pojo.Chengji;
import com.wczy.daoimpl.ChengjiDaoImpl;

public class SelectServlet extends HttpServlet {


	public SelectServlet() {
		super();
	}


	public void destroy() {
		super.destroy(); 
	}


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

		response.setContentType("text/html");
		doPost(request,response);

	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("GBK");
		request.setCharacterEncoding("GBK");
		response.setContentType("text/html");
		
		String id=request.getParameter("txtid");
		String name=request.getParameter("txtname");
		String yuwen=request.getParameter("txtyuwen");
		String shuxue=request.getParameter("txtshuxue");
		String yingyu=request.getParameter("txtyingyu");
		String operation = request.getParameter("operation");

		ChengjiDaoImpl chengjidao=new ChengjiDaoImpl();
		Chengji chengji=new Chengji();
		
		HttpSession session=request.getSession();
		
		if(operation.equals("isnew")){
		String sql="select * from chengji";
		ArrayList arr=chengjidao.select(sql);
		session.setAttribute("arr", arr);
		response.sendRedirect("/newtest/success3.jsp");
		}
		else if(operation.equals("增加")){
			String sql="select * from chengji";
			chengji.setId(Integer.parseInt(id));
			chengji.setName(name);
			chengji.setYuwen(Float.parseFloat(yuwen));
			chengji.setShuxue(Float.parseFloat(shuxue));
			chengji.setYingyu(Float.parseFloat(yingyu));
			chengjidao.isAddOk(chengji);
			ArrayList arr = chengjidao.select(sql);
			session.setAttribute("arr", arr);
			response.sendRedirect("/newtest/success.jsp");
		}
		else if(operation.equals("查找")){
			String sql="select * from chengji where 2>1";
			if(id!=null&&!id.equals("")){
				sql=sql+"and id="+id;
			}
			if(name!=null&&!name.equals("")){
				sql=sql+"and name like '%"+name+"%'";
			}
			if(yuwen!=null&&!yuwen.equals("")){
				sql=sql+"and yuwen="+yuwen;
			}
			if(shuxue!=null&&!shuxue.equals("")){
				sql=sql+"and shuxue="+shuxue;
			}
			if(yingyu!=null&&!yingyu.equals("")){
				sql=sql+"and yingyu="+yingyu;
			}
			ArrayList arr=chengjidao.select(sql);
			session.setAttribute("arr", arr);
			response.sendRedirect("/newtest/success.jsp");
		}
		else if(operation.equals("修改")){
			String sql="select * from chengji";
			String id1=request.getParameter("txtid");
			String name1=request.getParameter("txtname");
			String yuwen1=request.getParameter("txtyuwen");
			String shuxue1=request.getParameter("txtshuxue");
			String yingyu1=request.getParameter("txtyingyu");
			
			chengji.setId(Integer.parseInt(id1));
			chengji.setName(name1);
			chengji.setYuwen(Float.parseFloat(yuwen1));
			chengji.setShuxue(Float.parseFloat(shuxue1));
			chengji.setYingyu(Float.parseFloat(yingyu1));
			chengjidao.update(chengji);
			
			ArrayList arr = chengjidao.select(sql);
			session.setAttribute("arr", arr);
			response.sendRedirect("/newtest/success.jsp");
			}
		else if(operation.equals("删除")){
			String sql="select * from chengji";
			String id1=request.getParameter("txtid");
			chengji.setId(Integer.parseInt(id1));
			chengjidao.delete(chengji);
			ArrayList arr = chengjidao.select(sql);
			session.setAttribute("arr", arr);
			response.sendRedirect("/newtest/success.jsp");
		}

	}


	public void init() throws ServletException {
		
	}

}

⌨️ 快捷键说明

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