java后台怎么接收并解析前台传过来的json
1个回答
展开全部
package cn.iambestcoder.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.iambestcoder.bean.Student;
import cn.iambestcoder.mysql.ConnectMySql;
@WebServlet( name = "Score",urlPatterns = "/Score")
public class Score extends HttpServlet
{
private ArrayList<Student> list = new ArrayList<>();
private String ids[] = null;//学号
private String kinds[] = null;//考试种类
private String scores[] =null;//分数
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
ids = request.getParameterValues("id");
kinds = request.getParameterValues("kind");
scores = request.getParameterValues("score");
for(int i=0;i<scores.length;i++)
{
Student student = new Student(ids[i],null,kinds[i],new Integer(scores[i]));
list.add(student);
}
int code = new ConnectMySql().updateScore(list);
if(code == 0)//修改失败
{
PrintWriter writer = response.getWriter();
writer.write("Sorry");
writer.flush();writer.close();
}
else//修改成功
{
response.sendRedirect("index.jsp");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询