javaee--学生成绩录入与显示--Struts2标签的使用
类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标签的使用的更多相关文章
- mfc学生成绩录入与查询
1.声明结构体 struct Person{ char name[8]; char yuwen[8]; char math[8];}; 2.成绩录入 在"保存"按钮中实现以下代码 ...
- Java课程设计—学生成绩管理系统(201521123005 杨雪莹)
一.团队课程设计博客链接 学生成绩管理系统 二.个人负责模块或任务说明 学生成绩录入 显示所有学生信息 显示各科平均成绩 显示学生成绩(按降序排序) 三.自己的代码提交记录截图 四.自己负责模块或任务 ...
- struts2官方 中文教程 系列三:使用struts2 标签 tag
避免被爬,先贴上本帖地址:struts2 官方系列教程一:使用struts2 标签 tag http://www.cnblogs.com/linghaoxinpian/p/6901316.html 本 ...
- C项目实践--学生成绩管理系统
1.功能需求分析 学生成绩管理系统是对学生基本信息及成绩的管理.本程序主要实现了对学生的学号.姓名等基本信息以及各项学科成绩进行增加.删除.修改.查询和保存到磁盘文件等操作.主要功能描述如下: (1) ...
- Java学生成绩绩点管理系统
一.考试要求: 1.按照测试内容要求完成程序的设计与编程: 2.建立学号姓名文件夹,如:“信 1805-1 班 20180001 XXX”,将源程序文件保存在文件夹中,压缩成 rar 文件提交. 3. ...
- Java开学测试-学生成绩管理系统
题目: 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishiscore,networkscore ...
- java简单学生成绩管理系统
题目要求: 一. 数据结构要求:(5 分) 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishi ...
- java学生成绩管理系统
信1805-1 20183590 田庆辉 石家庄铁道大学 2019 年秋季 ...
- Java学生成绩系统
package text; public class helloworld{ private String stunumber; private String name; private double ...
随机推荐
- AOP(面向切面编程,翻译自MSDN)
目录 AOP的概念 静态实现AOP .Net 框架实现AOP(动态代理实现AOP) 动态代理AOP实现方法过滤 AOP参考 本文翻译自 :https://msdn.microsoft.com/en-u ...
- 路边拾遗之其他模块(struct/csv/xlwt/smtp)
struct模块 最近在学习python网络编程这一块,在写简单的socket通信代码时,遇到了struct这个模块的使用,当时不太清楚这到底有和作用,后来查阅了相关资料大概了解了,在这里做一下简单的 ...
- Java面向对象-static关键字、静态方法与普通方法、静态成员变量
Java面向对象-static关键字.静态方法与普通方法 static关键字的基本作用:方便在没有创建对象的情况下来进行调用(方法/变量). 很显然,被static关键字修饰的方法或者变量不需要依赖于 ...
- leetcode783
对BST树进行中序遍历,得到递增序列,然后依次计算相邻两元素之间的差,并保存最小的差. class Solution { public: vector<TreeNode*> V; void ...
- 自定义对话框<转>
效果如下: <ignore_js_op> QQ截图20130221234404.png (51.02 KB, 下载次数: 126) 下载附件 保存到相册 2013-2-21 23:44 ...
- MapReduce和YARN框架
MapReduce组件如图
- consul watch
consul watch -type key -key mhc ./key_handler.py [root@mhc consul]# cat key_handler.py #!/usr/bin/py ...
- 605. Can Place Flowers零一间隔种花
[抄题]: Suppose you have a long flowerbed in which some of the plots are planted and some are not. How ...
- Newtonsoft 序列化和反序列化特殊处理
1>序列化,时间格式化处理 JsonConvert.SerializeObject(Iar, new JsonSerializerSettings() { DateFormatString = ...
- 在CentOS6.x下安装Compiz——桌面立方体,特效种种
很多人貌似认为compiz必须要emerland,但事实上,没这个必要. compiz+gnome,实用,而又华丽,是个不错的选择. compiz需要显卡驱动,一般情况下不成问题(别忘了这是很新的ce ...