- 浏览: 151224 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
hx0637:
楼主!小弟要面临面试了,能否指导下小弟?
面试 深圳一家公司的 -
kljismi:
你好,我现在正在开这项目的代码,但是我不明白@Privileg ...
权限管理模块分析 -
yzhw:
终于找到了
ImageSizer.java -
sunloveny:
国
struts国际化 -
jackotty:
谢谢楼主的分享
struts validator验证框架
CalAction.java
CalActionForm.java
web.xml
struts-config.xml
index.jsp
input.jsp
success.jsp
error.jsp
package com.bjsxt.struts; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class CalAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { CalActionForm caf = (CalActionForm)form; int value1 = caf.getValue1(); int value2 = caf.getValue2(); String flag = caf.getFlag(); int result = 0; try { if ("+".equals(flag)) { result = value1 + value2; }else if ("-".equals(flag)) { result = value1 - value2; }else if ("*".equals(flag)) { result = value1 * value2; }else if ("/".equals(flag)) { result = value1 / value2; } request.setAttribute("result", result); return mapping.findForward("success"); }catch(Exception e) { e.printStackTrace(); } return mapping.findForward("error"); } }
CalActionForm.java
package com.bjsxt.struts; import org.apache.struts.action.ActionForm; public class CalActionForm extends ActionForm { private int value1; private String flag; private int value2; public int getValue1() { return value1; } public void setValue1(int value1) { this.value1 = value1; } public String getFlag() { return flag; } public void setFlag(String flag) { this.flag = flag; } public int getValue2() { return value2; } public void setValue2(int value2) { this.value2 = value2; } }
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- Standard Action Servlet Configuration (with debugging) --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- Standard Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <!-- <url-pattern>*.action</url-pattern> --> <url-pattern>/action/*</url-pattern> </servlet-mapping> </web-app>
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="calForm" type="com.bjsxt.struts.CalActionForm"/> </form-beans> <action-mappings> <action path="/cal" type="com.bjsxt.struts.CalAction" name="calForm" scope="request" attribute="testForm" > <forward name="success" path="/success.jsp"/> <forward name="error" path="/error.jsp"/> </action> </action-mappings> </struts-config>
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <% 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> <a href="input.jsp">简易计算器</a> </body> </html>
input.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>简易计算器</title> </head> <body> <h1>简易计算器</h1> <hr> <form action="action/cal" method="post"> <input type="text" name="value1"> <select name="flag"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" name="value2"> <input type="submit" value="="> </form> </body> </html>
success.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ page import="com.bjsxt.struts.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>成功信息</title> </head> <body> <% CalActionForm caf = (CalActionForm)request.getAttribute("testForm"); %> <%=caf.getValue1() %> <%=caf.getFlag() %> <%=caf.getValue2() %> = <%=request.getAttribute("result") %> </body> </html>
error.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ page import="com.bjsxt.struts.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>错误信息</title> </head> <body> <% CalActionForm caf = (CalActionForm)request.getAttribute("testForm"); %> 计算失败:<br> <%=caf.getValue1() %> <%=caf.getFlag() %> <%=caf.getValue2() %> </body> </html>
发表评论
-
drp_user
2009-01-11 15:10 1189采用DispathAction * 如果覆写DispathA ... -
编程式异常 -声明式异常
2009-01-11 11:28 14791、编程式异常 * 截获异常 * 创建相应的异常消息 * ... -
struts validator验证框架
2009-01-07 23:35 2902struts validator验证框架 1、配置: * ... -
struts国际化
2009-01-07 23:18 66631、struts国际化的配置 * 在struts-confi ... -
了解Locale
2009-01-07 23:01 12721、了解缺省Locale是由操作系统决定的,Locale是由语 ... -
actionmapping
2009-01-07 22:48 14091、struts-config.xml文件中,每个<ac ... -
ActionForward的使用
2009-01-07 22:13 41991、理解全局和局部ActionForward的概念 2、red ... -
分步收集,ActionForm的scope=session
2009-01-07 21:58 1732StartAction.java package com.b ... -
ActionForm
2009-01-07 20:06 14971、动态ActionForm 动态ActionForm是为了 ... -
DispatchAction.java
2009-01-07 19:48 1076/* * $Id: DispatchAction.java ... -
模式匹配
2009-01-07 19:41 779UserAction.java package com. ... -
jstl标签库的配置
2009-01-07 18:51 3412jstl标签库的配置 * 将jstl.jar和standar ... -
1.2.9 RequestProcessor.java
2008-12-27 17:47 1301/* * $Id: RequestProcessor.ja ... -
1.2.9 ActionServlet.java
2008-12-27 17:43 1206/* * $Id: ActionServlet.java ... -
struts_login
2008-12-27 17:32 9071、配置struts * 拷贝struts lib下的所有j ... -
bjsxt test_servlet
2008-12-26 22:46 1126TestServlet.java package com. ...
相关推荐
6. **03_struts_trainnig_cal**: 可能是一个日历或者训练计划管理的应用,展示了Struts处理复杂业务逻辑的能力,比如数据持久化、事务管理等。 7. **07_struts_actionform**: ActionForm是Struts中的表单类,它用于...
项目文件`struts_trainnig_cal`可能包含以下内容: 1. `struts-config.xml`:这是Struts1的配置文件,定义了Action的映射、数据源、消息资源等。 2. `web.xml`:Web应用的部署描述符,配置了Servlet和过滤器,包括...
Trainnig-React-2020年3月
提供的实训资料《Trainnig_base》可能包括系统源代码、设计文档、测试数据等,学生可以通过阅读源代码学习单链表的实现方式,结合设计文档理解系统的整体架构,利用测试数据进行功能验证和性能优化。 总结,图书...
对于Trainnig,您自己的数据需要具有自己的数据手套。 设置 使用aruino将手套连接到笔记本电脑。 现在,您需要在arduino上运行sketch_jun15a.ino。 为了将数据从aruino传输到Excel,我使用了Aduino Excel 2.1。 关联...