jsp成绩单综合设计

1.jsp

输入老师姓名,班级名称,科目数,学生人数。

<body>
<p align="center">成绩单制作系统</p>
<hr width="250">
<form name="form1" method="post" action="2.jsp">
  <table width="360" border="1" align="center">
    <tr>
      <td align="right">老师姓名:</td>
      <td><input name="teachername" type="text" ></td>
    </tr>
    <tr>
      <td  align="right">班级名称:</td>
      <td><input type="text" name="classname" ></td>
    </tr>
    <tr>
      <td align="right">科目数:</td>
      <td><input type="text" name="coursenum"></td>
    </tr>
    <tr>
      <td align="right">学生人数:</td>
      <td><input type="text" name="stunum" id="stunum"></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input type="submit" name="button" id="button" value="确定">
      <input type="reset" name="button2" id="button2" value="重置"></td>
    </tr>
  </table>
</form>
</body>
2.jsp

输入科目名称。

<body>
<%
	request.setCharacterEncoding("utf-8");
	String teachername=request.getParameter("teachername");
	String classname=request.getParameter("classname");
	int cn=Integer.parseInt(request.getParameter("coursenum"));
	int sn=Integer.parseInt(request.getParameter("stunum"));	
	session.setAttribute("teachername",teachername );
	session.setAttribute("classname",classname );
	session.setAttribute("cn",cn );
	session.setAttribute("sn",sn );	
%>
<p align="center"><strong>请输入科目名称</strong></p>
<hr width="250">
<p align="center"><font size=5 color="red">老师姓名:<%=teachername %> 班级名称:<%=classname %> 学生人数:<%= sn%></font></p>

<form name="form1" method="post" action="3.jsp">
  <table width="0" border="1" align="center">
  
 <%
 	for(int i=0;i<cn;i++){
 %>
    <tr>
      <td>科目<%=i+1 %>名称</td>
      <td><input type="text" name="coursename[<%=i%>]" ></td>
    </tr>
    <%
 	}
%>   
    <tr>
   <td colspan="2" align="center"><input type="submit" name="button" id="button" value="确定">
      <input type="submit" name="button2" id="button2" value="重置"></td>
    </tr>
  </table>
</form>
</body>
3.jsp

输入学生姓名及各科成绩。

<body>
<%
	request.setCharacterEncoding("utf-8");
	String teachername=(String)session.getAttribute("teachername");
	String classname=(String)session.getAttribute("classname");
	int sn=(Integer)session.getAttribute("sn");
	int cn=(Integer)session.getAttribute("cn");
	
	//接收课程名的数组
	String coursename[]=new String[cn];
	for(int i=0;i<cn;i++){
		coursename[i]=request.getParameter("coursename["+i+"]");
	}	
	session.setAttribute("cname", coursename);
%>


<p align="center">请输入学生的姓名及各科成绩</p>
<hr width="250">
<p align="center"><font size=5 color="red">老师姓名:<%=teachername %> 班级名称:<%=classname %> 学生人数:<%= sn%></font></p>

<form name="form1" method="post" action="4.jsp">
  <table width="456" border="1" align="center" >
    <tr>
      <td width="234">学生姓名</td>
      <%for(int i=0;i<cn;i++){ %>
      <td width="206"><%= coursename[i]%>成绩</td>
      <%} %>
    </tr>
    
  <%for(int i=0;i<sn;i++){%>    
    <tr>
      <td><input type="text" name="stuname[<%=i%>]" id="stuname"></td>
      <%for(int j=0;j<cn;j++){ %>
      <td><input type="text" name="score[<%=i %>][<%=j %>]" id="score"></td>
      <%} %>
    </tr>
    <%}%>       
  </table>
  <p align="center">
      <input type="submit" name="button" id="button" value="确定">
      <input type="submit" name="button2" id="button2" value="重置">
  </p>
</form>

</body>

4.jsp

学生成绩单,包括各科成绩以及总分和平均分。

<body>
	<%
		request.setCharacterEncoding("utf-8");
		String teachername = (String) session.getAttribute("teachername");
		String classname = (String) session.getAttribute("classname");
		int sn = (Integer) session.getAttribute("sn");
		int cn = (Integer) session.getAttribute("cn");

		String[] cname = (String[]) session.getAttribute("cname");
		String[] stuname = new String[sn];
		int[][] score = new int[sn][cn];

		int[] sum = new int[sn];
		int[] ave = new int[sn];

		for (int i = 0; i < sn; i++) {
			stuname[i] = request.getParameter("stuname[" + i + "]");
			for (int j = 0; j < cn; j++) {
				score[i][j] = Integer.parseInt(request.getParameter("score[" + i + "][" + j + "]"));
				sum[i] += score[i][j];
			}
			ave[i] = sum[i] / cn;
		}
	%>
	<p align="center">学生成绩单</p>
	<hr align="center" width="360">

	<p align="center">
		<strong><font color="red" size=3> 老师姓名:<%=teachername%>
				班级名称:<%=classname%> 学生人数:<%=sn%>
		</font>
	</p>

	<form name="form1" method="post" action="">
		<table border="1" align="center" cellspacing="0">
			<tr bgcolor="yellow">
				<td>学生姓名</td>
				<%
					for (int i = 0; i < cn; i++) {
				%>
				<td><%=cname[i]%>成绩</td>
				<%
					}
				%>
				<td>总分</td>
				<td>平均分</td>
			</tr>

			<%
				for (int i = 0; i < sn; i++) {
			%>
			<tr bgcolor="green">
				<td><%=stuname[i]%></td>
				<%
					for (int j = 0; j < cn; j++) {
				%>
				<td><%=score[i][j]%></td>
				<%
					}
				%>
				<td><%=sum[i]%></td>
				<td><%=ave[i]%></td>
			</tr>
			<%
				}
			%>
		</table>
	</form>
</body>

5.思考:优化代码,减少重复。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值