首页 > 代码库 > Ajax些成绩批量录入

Ajax些成绩批量录入

1.jsp,ajax的循环调用,必须要递归,否则会出错。

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="http://www.mamicode.com/">
    
    <title>My JSP ‘Scoreinsert.jsp‘ starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="http://www.mamicode.com/js/jquery.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="http://www.mamicode.com/styles.css">
	-->

  </head>
  <script type="text/javascript">
 
function sub(i)
{ 

var a = $("table tr").eq(i).children("td").eq(0).children().val();
var b = $("table tr").eq(i).children("td").eq(0).children().eq(1).val();
var c = $("table tr").eq(i).children("td").eq(1).children().val();
var d = $("table tr").eq(i).children("td").eq(2).children().val();
var e = $("table tr").eq(i).children("td").eq(3).children().val();
aja2(a,b,c,d,e,i);
}
function aja2(a,b,c,d,e,i){

 $.ajax({
    url:‘BatchScoreSave.action‘,
    type:‘POST‘, //GET
    async:true,    //或false,是否异步
    data:{    
    classs:a,
    course:b,
    number:c,
    name:d,
    scores:e
    },//提交表单数据
    timeout:5000,    //超时时间
    dataType:‘json‘,    //返回的数据格式:json/xml/html/script/jsonp/text
    success:function(data){		  
        //console.log(data);
       console.log(‘成功‘);      
       if(i<$("table tr").length-1){
       i++;
       sub(i);
       
       }
    },
    error:function(xhr,textStatus){
        console.log(‘错误‘);
    },
}); 


}


  </script>
  <body>
  <s:property value="http://www.mamicode.com/classs"/>班<s:property value="http://www.mamicode.com/course"/>成绩录入
  
  <table  cellpadding="10" border="1">
       <tr>
       <th>班级</th>
       <th>学号</th>
       <th>姓名</th>
       <th>成绩</th>
       <th>操作</th>
       </tr>    
       <s:iterator value="http://www.mamicode.com/scorelist">    
       <tr>
       <form action="ScoreSave.action">
       <td><input type="text" name="classs" value=http://www.mamicode.com/‘

 2.action,就是简单的一条数据一条数据的保存,一定有get和set,注意Spring注入不能写get,会报错。

public String BatchScoreSave() throws Exception{
		score = new Score();
		score.setId(new ScoreId());
		score.getId().setClasss(classs);
		score.getId().setCourse(course);
		score.getId().setNumber(number);
		score.getId().setName(name);
		score.getId().setScore(scores);
		mgr.Scoresave(score);
		
		return SUCCESS;
	}

 3.struts.xml

<package name="aaa" extends="json-default">

  

<action name="BatchScoreSave" class="ScoreAction" method="BatchScoreSave">
			<result name="success" type="json">
			<param name="root"></param>
			</result></action>

4.结果截图

技术分享

 

Ajax些成绩批量录入