one by one 项目 part 6

package Controllerservlet;

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 bean.student;

public class FormCheck extends HttpServlet {

	/**
		 * Constructor of the object.
		 */
	public FormCheck() {
		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 {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		HttpSession session= request.getSession(); 
		ArrayList<student> list = (ArrayList<student>)session.getAttribute("list");
		System.out.println(1122222);
        for(int i=0;list!=null&&i<list.size();i++){
        	System.out.println(111);
			String jj = request.getParameter("blogmark"+i);
			if (!jj.equals("")){
				student s = list.get(i);
				String cc=s.getId();
				String zz=s.getName();
				String  sql="update studentinfo set blogmark="+jj+" where name = '"+zz+"'and id="+cc+"";
				System.out.println(sql);
				 studentservlet.DbUtil  run=new studentservlet.DbUtil();
				   int n=run.updateSQL(sql);
				   if(n>=1)
					   out.print("操作成功");
				   else
					   out.print("操作失败");
			      }
		}
			
			
		
	}

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

		doGet(request, response);
	}

	/**
		 * Initialization of the servlet. <br>
		 *
		 * @throws ServletException if an error occurs
		 */
	public void init() throws ServletException {
		// Put your code here
	}

}

  

实现一组数据的插入

数据库截图

 

posted @ 2017-12-13 22:54  橘柑之味  阅读(155)  评论(0编辑  收藏  举报