input_score.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<form action="score.action" method="post"> 用户名: <input name="sname" /><br/>
成绩: <input name="score" /><br/>
补考成绩: <input name="score2" /><br/>
<input type="submit" value="注册"/>
</form>
</body>
</html>

  

showscore.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'show.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
${sname },${score }
</body>
</html>

  

showerror.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
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>My JSP 'showerror.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
出错信息如下:<s:fielderror/>
</body>
</html>

  

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="p" namespace="/" extends="struts-default">
<action name="score" class="com.etc.action.ScoreAction">
<result>
/showscore.jsp
</result>
<result name="input">
/showerror.jsp
</result>
</action>
</package>
</struts>

  

ScoreAction

package com.etc.action;

import com.opensymphony.xwork2.ActionSupport;

public class ScoreAction extends ActionSupport
{
private String sname;
private Integer score;
private Integer score2;
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
} /*
@Override
public void validate()
{
if(score<0||score>60)
this.addFieldError("score","成绩非法!");
}
*/ public Integer getScore() {
return score;
}
public void setScore(Integer score) {
this.score = score;
}
public Integer getScore2() {
return score2;
}
public void setScore2(Integer score2) {
this.score2 = score2;
}
public String execute()
{
return "success";
} }

  

ScoreAction-validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.2//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
<validator type="requiredstring"><!-- 必填字符串字段 -->
<param name="fieldName">sname</param>
<message>uid不能为空</message>
</validator> <validator type="required"><!-- 必填字段 -->
<param name="fieldName">score</param>
<message>score不能为空</message>
</validator> <validator type="required"><!-- 必填字段 -->
<param name="fieldName">score2</param>
<message>score2不能为空</message>
</validator> <validator type="int"> <!-- 整数校验器 -->
<param name="fieldName">score</param>
<param name="max">100</param>
<param name="min">0</param>
<message>成绩必须在${min}-${max}之间!</message>
</validator> <validator type="int"> <!-- 整数校验器 -->
<param name="fieldName">score2</param>
<param name="max">100</param>
<param name="min">60</param>
<message>补考成绩必须在${min}-${max}之间!</message>
</validator> </validators>

  

validators.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator Config 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd"> <!-- START SNIPPET: validators-default -->
<validators>
<validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
<validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
<validator name="long" class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
<validator name="short" class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
<validator name="double" class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
<validator name="date" class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
<validator name="expression" class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
<validator name="email" class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
<validator name="url" class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
<validator name="visitor" class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
<validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
<validator name="regex" class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
<validator name="conditionalvisitor" class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
<validator name="myusername" class="com.etc.validator.MyUsernameValidator"/>
</validators>
<!-- END SNIPPET: validators-default -->

  

最新文章

  1. Noise Contrastive Estimation
  2. C++ 构造函数、析构函数、拷贝构造、赋值运算符
  3. 前端Mvvm QC 设计解析
  4. unittest框架介绍
  5. java学习第5天
  6. java核心知识点学习----创建线程的第三种方式Callable和Future CompletionService
  7. 全局变量报错:UnboundLocalError: local variable &#39;l&#39; referenced before assignment
  8. Android入门之GridView(表格控件)
  9. always语言指导原则
  10. CentOS搭建VSFTP
  11. jQuery 选择器【1】
  12. Installshield设置feature为必须选中状态,即必定安装状态
  13. VMware Workstation 无法与 Windows XP \ Windows 7 \ Windows 8 进行共享文件夹。
  14. 12、借助Jacob实现Java打印报表(Excel、Word)
  15. linux学习:特殊符号,数学运算,图像与数组与部分终端命令用法整理
  16. 用oracle自带的ssh脚本配置互信
  17. windows server 2012 远程桌面不好使
  18. 移动APP用例设计中的关键点(转载)
  19. InstallShield 读注册表函数 RegDBGetKeyValueEx ()执行失败
  20. SSM项目 单元测试中 注入bean 空指针异常

热门文章

  1. window7 共享wifi(不通过wifi软件)
  2. 【转】Android ImageView的scaleType属性与adjustViewBounds属性
  3. 逆向破解学习二之&lt;TraceMe&gt;
  4. 求两个有序序列合并成新有序序列的中位数,求第k小数
  5. EF-简化排序
  6. jenkins自动发送邮件配置
  7. ubuntu16.04下安装配置深度学习环境(Ubuntu 16.04/16.10+ cuda7.5/8+cudnn4/5+caffe)
  8. ionic3 教程(一)安装和配置
  9. js杨辉三角
  10. filter()和sort()这两个方法一块学习,案例中。