JavaWeb -- JSP+JavaBean模式
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>简单计算器</title>
</head>
<body style="text-align: center;"> <jsp:useBean id="calculator" class="com.kevin.Calculator"></jsp:useBean>
<jsp:setProperty property="*" name="calculator"/>
<%
calculator.operation();
%>
<br />-----------------------------------------------------------<br />
<jsp:getProperty property="input1" name="calculator"/>
<jsp:getProperty property="oper" name="calculator"/>
<jsp:getProperty property="input2" name="calculator"/>=
<jsp:getProperty property="result" name="calculator"/>
<br />-----------------------------------------------------------<br /> <form action="/WebTest4/calculator.jsp" method="post">
<table width="40%" border="1">
<tr>
<td colspan="2">简单计算器</td>
</tr> <tr>
<td>第一个参数</td>
<td><input type="text" name="input1" /> </td>
</tr> <tr>
<td>运算符</td>
<td>
<select name="oper">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
</tr> <tr>
<td>第二个参数</td>
<td><input type="text" name="input2" /> </td>
</tr> <tr style="text-align: right;">
<td colspan="2" ><input type="submit" name="bt1" value="计算"/></td>
</tr>
</table>
</form> </body>
</html>
javabean类
package com.kevin; import java.math.BigDecimal; import javax.management.RuntimeErrorException; public class Calculator {
private String input1="0";;
private String input2="0";
private String oper="+";
private String result="0"; public void operation()
{
BigDecimal first = new BigDecimal(input1);
BigDecimal second = new BigDecimal(input2); System.out.println("oper: " + oper); if( oper.equals("+") )
result = first.add(second).toString();
else if( oper.equals("-") )
result = first.subtract(second).toString();
else if( oper.equals("*") )
result = first.multiply(second).toString();
else if( oper.equals("/") )
{
if( second.doubleValue()==0 )
{
result = "除数不能为0";
return;
}
if( second.doubleValue() > first.doubleValue() )
{
result = "除数不要大于被除数";
return;
}
result = first.divide(second).toString();
}
else
throw new RuntimeException("元算符异常"); } public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getInput1() {
return input1;
}
public void setInput1(String input1) {
this.input1 = input1;
}
public String getInput2() {
return input2;
}
public void setInput2(String input2) {
this.input2 = input2;
}
public String getOper() {
return oper;
}
public void setOper(String oper) {
this.oper = oper;
} }
JavaWeb -- JSP+JavaBean模式的更多相关文章
- JavaWeb实现用户登录注册功能实例代码(基于Servlet+JSP+JavaBean模式)
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- javaweb学习总结(二十二)——基于Servlet+JSP+JavaBean开发模式的用户登录注册
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- JavaWeb学习 (二十一)————基于Servlet+JSP+JavaBean开发模式的用户登录注册
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- javaweb(二十二)——基于Servlet+JSP+JavaBean开发模式的用户登录注册
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- 咸鱼入门到放弃11--Servlet+JSP+JavaBean开发模式
本篇搬运了大佬blog:https://www.cnblogs.com/xdp-gacl/p/3902537.html 一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servle ...
- 基于Servlet+JSP+JavaBean开发模式的用户登录注册
http://www.cnblogs.com/xdp-gacl/p/3902537.html 一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBea ...
- javaweb基础(22)_Servlet+JSP+JavaBean实战登陆
一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...
- JSP中使用的模式——JSP+JavaBean
模式二:JSP+Servlet+JavaBean 链接地址:http://wxmimperio.coding.io/?p=189 JSP中两种模式的总结 链接地址:http://wxmimperio. ...
- jsp javabean开发模式
JSP&&JavaBean开发模式 在jsp+javabean架构中,jsp负责控制逻辑,表现逻辑,业务对象的调用 jsp+javaBean模式适合开发业务逻辑不复杂的web应用,这种 ...
随机推荐
- EasyNVR互联网监控直播分发出RTMP、HLS、HTTP-FLV视频流说明介绍
背景需求 需求比视频流协议更重要,你想要什么,什么可以满足你的需求,这个很大程度上是需求在前,选择使用什么视频流是比较靠后的. 目前Easy系列互联网直播服务将全线支持HLS.RTMP.HTP-FLV ...
- javascript中字符串截取的两种方法
var testStr = "hello kay!"; 1.substr testStr.substr(1) ->ello kay! testStr.substr(1,4 ...
- p:nth-last-child(2)
<!DOCTYPE html><html><head><style> p:nth-last-child(2){background:#ff0000;}& ...
- event对象及各种事件
事件(event) event对象 (1)什么是event对象? Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态.事件通常与函数结合使用,函数不会 ...
- ECMAScript6补全字符串长度方法padStart()和padEnd()
一.padStart() 1.定义 padStart()方法用另一个字符串(默认为空格)重复填充到对象字符串到指定长度,填充从对象字符串左侧开始,返回新的字符串. 2.语法 str.padStart( ...
- Linux中的判断式
格式一:test [参数] 判断内容格式二:[ [参数] 判断内容 ] 说明: a.格式二可以认为是格式一的缩写 b.格式二里中括号和内容之间要有空格 基于文件的判断-d 判断文件是否存在,并且是目录 ...
- Python多进程multiprocessing
import multiprocessing import time # 具体的处理函数,负责处理单个任务 def func(msg): # for i in range(3): print (msg ...
- 20170517 ABAP debug
1.新版本调试模式下的观察点: 在新版本模式画面的工具栏上选择'watchpoint' 按钮可以创建观察点. 举例:当生产内表itab第5行时,设置为观察点,追加条件如下: Lines(itab) = ...
- SaltStack远程执行shell脚本
编辑文件fansik.sh 脚本内容: #!/bin/bash # Author: fansik # data: 2017年 09月 26日 星期二 :: CST touch /tmp/fansik. ...
- Java智能图表类库JChartLib使用介绍
http://www.codeceo.com/article/java-jchartlib.html JChartLib是一款基于Java的智能图表类库,JChartLib不仅有着漂亮的外观,而且支持 ...