类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. Rest之路 - 第一个Rest程序

    在 Eclipse 里新建一个 Dynamic project 将 Jersey 的 jar 包,拷贝到 WebContent -> WEB-INF -> lib 文件夹 Add jars ...

  2. TEMP2

  3. windows下安装ubuntu 12.04---利用ubuntu的iso包中的wubi.exe工具安装

    一.下载ubuntu-12.04-desktop-amd64.iso后,用winrar打开,提取出wubi.exe这个文件.把ubuntu-12.04-desktop-amd64.iso和wubi.e ...

  4. Subscript & Inheritance

    [Subscript] 1.subscript的定义: 2.Subscript的使用: 3.可以定义多维subscript: 多维Subscript的使用: [Inheritance] 1.overr ...

  5. AJAX省市县三级联动的实现

    省市县数据 本例子中省市县数据保存在MySQL数据库中,部分数据截图如下: 从数据库中读取数据 导入需要的jar包 连接池配置文件 <c3p0-config> <!-- 默认配置,如 ...

  6. 【bzoj2818】Gcd

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4344  Solved: 1912[Submit][Status][Discuss ...

  7. LoadRunner 事物

    添加事物 Action() { lr_start_transaction("openindex"); web_url("WebTours", "URL ...

  8. 张超超OC基础回顾01_类的创建,申明属性,以及本质

    一. 类的声明和实现&规则 1.如何编写类的声明 以@interface开头 , 以@end结尾, 然后再class name对应的地方写上 事物名称, 也就是类名即可 注意: 类名的首字符必 ...

  9. hadoop 2.7.3 (hadoop2.x)使用ant制作eclipse插件hadoop-eclipse-plugin-2.7.3.jar

    为了做mapreduce开发,要使用eclipse,并且需要对应的Hadoop插件hadoop-eclipse-plugin-2.7.3.jar,首先说明一下,在hadoop1.x之前官方hadoop ...

  10. Anaconda( different versions) configuration in ubuntu 14

    1. 安装自己经常使用的Anaconda版本 sh ./Anaconda3-5.0.1-Linux-x86_64.sh 2. 默认安装到 /home/usr/anaconda3下面,在anaconda ...