类Score.java:各课程的成绩及平均成绩

类Student.java:学生姓名、学号及Score类

类ScoreAction.java:将Student类存在一个List对象中, execute()方法根据用户输入的成绩计算每个学生的平均成绩。

页面scores.jsp:完成录入学生信息及考试成绩

页面showScores.jsp:显示已录入的学生成绩及平均成绩

效果如下:

代码如下:

 package javaBean;

 public class Score {
private int javaScore;
private int j2eeScore;
private int ccScore;
private double aveScore;
public int getJavaScore() {
return javaScore;
}
public void setJavaScore(int javaScore) {
this.javaScore = javaScore;
}
public int getJ2eeScore() {
return j2eeScore;
}
public void setJ2eeScore(int j2eeScore) {
this.j2eeScore = j2eeScore;
}
public int getCcScore() {
return ccScore;
}
public void setCcScore(int ccScore) {
this.ccScore = ccScore;
}
public double getAveScore() {
return aveScore;
}
public void setAveScore(double aveScore) {
this.aveScore = aveScore;
}
}

Score

 package javaBean;

 public class Student {
private String name;
private long number;
private Score score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getNumber() {
return number;
}
public void setNumber(long number) {
this.number = number;
}
public Score getScore() {
return score;
}
public void setScore(Score score) {
this.score = score;
}
}

Student

 package actions;

 import java.math.BigDecimal;
import java.util.List; import com.opensymphony.xwork2.ActionSupport; import javaBean.Score;
import javaBean.Student; public class ScoreAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private List<Student> students; public List<Student> getStudents() {
return students;
} public void setStudents(List<Student> students) {
this.students = students;
}
public String execute() throws Exception{
int size = students.size();
for(int i=0; i<size; i++){
Student st = students.get(i);
Score score = st.getScore();
double aveScore = (score.getJavaScore() + score.getCcScore() +
score.getJ2eeScore()) / 3.0;
BigDecimal b = new BigDecimal(aveScore);
aveScore = b.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
score.setAveScore(aveScore);
}
return super.SUCCESS;
}
}

ScoreAction

 <%@ 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="<%=basePath%>"> <title>输入学生成绩</title> <s:head theme="xhtml" />
<style type="text/css">
table {
border-collapse: collapse;
border: 1px solid #000;
} th, td {
border: 1px solid #000;
}
</style>
</head>
<body>
<s:form theme="simple" action="showscores" namespace="/" >
<table>
<thead>
<tr>
<th align="center">姓名</th>
<th align="center">学号</th>
<th align="center">Java成绩</th>
<th align="center">C语言成绩</th>
<th align="center">J2EE成绩</th>
</tr>
</thead>
<tbody>
<s:iterator value="new int[4]" status="st">
<tr>
<td><s:textfield name="%{'students['+#st.index+'].name'}"></s:textfield>
</td>
<td><s:textfield name="%{'students['+#st.index+'].number'}"></s:textfield>
</td>
<td><s:textfield
name="%{'students['+#st.index+'].score.javaScore'}"></s:textfield>
</td>
<td><s:textfield
name="%{'students['+#st.index+'].score.ccScore'}"></s:textfield></td>
<td><s:textfield
name="%{'students['+#st.index+'].score.j2eeScore'}"></s:textfield>
</td>
</tr>
</s:iterator>
</tbody>
</table>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>

scores.jsp

 <%@ 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="<%=basePath%>"> <title>显示学生信息</title>
<s:head theme="xhtml" />
<style type="text/css">
table {
border-collapse: collapse;
border: 1px solid #000;
} th, td {
border: 1px solid #000;
}
</style>
</head> <body>
<table>
<thead>
<tr>
<th align="center">姓名</th>
<th align="center">学号</th>
<th align="center">Java成绩</th>
<th align="center">C语言成绩</th>
<th align="center">J2EE成绩</th>
<th align="center">平均成绩</th>
</tr>
</thead>
<tbody>
<s:iterator value="students" status="st">
<tr>
<td align="center"><s:property value="name" /></td>
<td align="center"><s:property value="number" /></td>
<td align="center"><s:property value="score.javaScore" /></td>
<td align="center"><s:property value="score.ccScore" /></td>
<td align="center"><s:property value="score.j2eeScore" /></td>
<td align="center"><s:property value="score.aveScore" /></td>
</tr>
</s:iterator> </tbody>
</table>
</body>
</html>

showScores.jsp

 <action name="scores">
<result>/scores.jsp</result>
</action>
<action name="showscores" class="actions.ScoreAction">
<result name="success">/showScores.jsp</result>
</action>

struts.xml

javaee--学生成绩录入与显示--Struts2标签的使用的更多相关文章

  1. mfc学生成绩录入与查询

    1.声明结构体 struct Person{ char name[8]; char yuwen[8]; char math[8];}; 2.成绩录入 在"保存"按钮中实现以下代码 ...

  2. Java课程设计—学生成绩管理系统(201521123005 杨雪莹)

    一.团队课程设计博客链接 学生成绩管理系统 二.个人负责模块或任务说明 学生成绩录入 显示所有学生信息 显示各科平均成绩 显示学生成绩(按降序排序) 三.自己的代码提交记录截图 四.自己负责模块或任务 ...

  3. struts2官方 中文教程 系列三:使用struts2 标签 tag

    避免被爬,先贴上本帖地址:struts2 官方系列教程一:使用struts2 标签 tag http://www.cnblogs.com/linghaoxinpian/p/6901316.html 本 ...

  4. C项目实践--学生成绩管理系统

    1.功能需求分析 学生成绩管理系统是对学生基本信息及成绩的管理.本程序主要实现了对学生的学号.姓名等基本信息以及各项学科成绩进行增加.删除.修改.查询和保存到磁盘文件等操作.主要功能描述如下: (1) ...

  5. Java学生成绩绩点管理系统

    一.考试要求: 1.按照测试内容要求完成程序的设计与编程: 2.建立学号姓名文件夹,如:“信 1805-1 班 20180001 XXX”,将源程序文件保存在文件夹中,压缩成 rar 文件提交. 3. ...

  6. Java开学测试-学生成绩管理系统

    题目: 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishiscore,networkscore ...

  7. java简单学生成绩管理系统

    题目要求: 一. 数据结构要求:(5 分) 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishi ...

  8. java学生成绩管理系统

                                                       信1805-1 20183590 田庆辉             石家庄铁道大学 2019 年秋季 ...

  9. Java学生成绩系统

    package text; public class helloworld{ private String stunumber; private String name; private double ...

随机推荐

  1. 010. VS2015创建MVC项目

    1. 文件→新建→项目 2.选择空模板→选中MVC 3. 预览(如果是使用aspx, 则可以删除Views中的web.config, 如果使用Razor则不要删除, 否则会报Views/Home/In ...

  2. springboot成神之——spring jdbc的使用

    本文介绍spring jdbc的使用 目录结构 pom配置 properties配置 model层User类 Dao层QueryForListDao config层AppConfiguration 程 ...

  3. js(react.js) button click 事件无法触发

    今天遇到一个诡异的问题.button 上的点击事件触发不了. 找个几个小时,原因是 js 报错了. <Button type="primary" htmlType=" ...

  4. 实例解说Linux命令行uniq

    Linux命令uniq的作用是过滤重复部分显示文件内容,这个命令读取输入文件,并比较相邻的行.在正常情况下,第二个及以后更多个重复行将被删去,行比较是根据所用字符集的排序序列进行的.该命令加工后的结果 ...

  5. windows上输入其他国家语言

    1.安装语言环境 2.先有语言环境再有该语言下的输入法toolkit工具集. 3.通过特定语言的属性可以查看键盘布局.

  6. textarea标签提示录入剩余字数

    textarea标签提示录入剩余字数 <textarea onkeydown="checkMaxInput(this,300)" onkeyup="checkMax ...

  7. get-task-allow有什么用

    [failed to get the task for process问题] A: Why am I getting "Error launching remote program: fai ...

  8. AC自动机详解

    概述 AC自动机全称Aho-Corasick automaton,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法. 考虑这样一个场景,给出L个模式字符串(加总长度为N),以及长度为M大文本, ...

  9. powerdesigner设计的pdm模型导出清晰图片格式

    用powerdesigner设计了数据库模型,想把模型粘贴到数据库文档中,之前一直是Ctrl+A然后复制,直接粘贴过去的,这次领导说放大看不清,o(╯□╰)o 没办法,得搞个高清图复制上去啊,怎么办呢 ...

  10. id 和 instancetype 方法的区别

    首先明确 id 和 instancetype 都是万能指针,都能指向一个对象:(instancetype == id == 万能指针 == 指向一个对象) 主要区别亮点: 1. id 在编译时候不能判 ...