制作简易计算器处理过程Servlet
CalculationServlet.java:
package com.you.servlet; import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.you.model.Calculator; /**
*
* 类功能说明
* 类改动者 改动日期
* 改动说明
* <p>Title:CalculationServlet.java</p>
* <p>Description:游海东个人开发</p>
* <p>Copyright:Copyright(c)2013</p>
* @author:游海东
* @date:2014-6-15 下午10:52:42
* @version V1.0
*/
public class CalculationServlet extends HttpServlet
{
/**
* @Fields serialVersionUID:序列化
*/
private static final long serialVersionUID = 1L; /**
* Constructor of the object.
*/
public CalculationServlet()
{
super();
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doPost(request, response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//操作数一
String operandOne=request.getParameter("operandOne");
//操作数二
String operandTwo=request.getParameter("setOperandTwo");
//运算符
String operator=request.getParameter("operator");
//计算结果
double calResult=0; Calculator cal=new Calculator();
//将字符串转换成double
cal.setOperandOne(Double.parseDouble(operandOne));
cal.setOperandTwo(Double.parseDouble(operandTwo)); //加法
if(operator.equals("+"))
{
calResult=cal.addition();
}
//减法
else if(operator.equals("-"))
{
calResult=cal.subtraction();
}
//乘法
else if(operator.equals("*"))
{
calResult=cal.multiplication();
}
//除法
else if(operator.equals("/"))
{
calResult=cal.division();
}
request.setAttribute("calResult", calResult);
request.getRequestDispatcher("/resultServlet").forward(request, response);
out.print(calResult);
} /**
* Destruction of the servlet. <br>
*/
public void destroy()
{
super.destroy();
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException
{ } }
制作简易计算器处理过程Servlet的更多相关文章
- 制作简易计算器处理结果Servlet
ResultServlet.java: package com.you.servlet; import java.io.IOException; import java.io.PrintWriter; ...
- Vue 制作简易计算器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 用js制作简易计算器及猜随机数字游戏
<!doctype html><html><head> <meta charset="utf-8"> <title>JS ...
- 大一C语言学习笔记(10)---编程篇--制作简易计算器,支持加,减,乘,除,取余运算,要求 0 bug
博主自开学初就一直在努力为自己的未来寻找学习方向,学习编程嘛,尽量还是要抱大腿的,所以我就加入了我们学校的智能设备研究所,别的不说,那的学长们看起来是真的很靠谱,学长们的学习氛围也超级浓厚,所以我就打 ...
- 利用Unity3D制作简易2D计算器
利用Unity3D制作简易2D计算器 标签(空格分隔): uiniy3D 1. 操作流程 在unity3DD中创建一个新项目 注意选择是2D的(因为默认3D) 在Assets框右键新建C#脚本 在新建 ...
- 制作一个简易计算器——基于Android Studio实现
一个计算器Android程序的源码部分分为主干和细节两部分. 一.主干 1. 主干的构成 计算器的布局 事件(即计算器上的按钮.文本框)监听 实现计算 2. 详细解释 假设我们的项目名为Calcula ...
- 菜鸟学习Struts——简易计算器
这是学习Struts的一个简单的例子文件结构如下: 1.配置Struts环境 2.新建input.jsp,success.jsp,error.jsp input.jsp代码如下: <%@ pag ...
- Python之实现一个简易计算器
自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...
- C#制作简易屏保(转)
C#制作简易屏保[原创] 原始网址: http://www.cnblogs.com/drizzlecrj/archive/2006/10/06/522182.html 2006-10-06 16:25 ...
随机推荐
- 怎样在Ubuntu上安装最新版本号的Node.js
怎样在Ubuntu上安装最新版本号的Node.js 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Node.js是一个软件平台,通经常使用于构建大规模的 ...
- 黑马程序员:Java基础总结----类加载器
黑马程序员:Java基础总结 类加载器 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个 ...
- Adaboost的几个人脸检测网站
[1]基础学习笔记之opencv(1):opencv中facedetect例子浅析 http://www.cnblogs.com/tornadomeet/archive/2012/03/22/2411 ...
- HDOJ 4964 Emmet
递归语法翻译... Emmet Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- hbase基本概念和hbase shell经常使用命令使用方法
HBase是一个分布式的.面向列的开源数据库,源于google的一篇论文<bigtable:一个结构化数据的分布式存储系统>.HBase是Google Bigtable的开源实现,它利用H ...
- python手记(46)
#!/usr/bin/env python # -*- coding: utf-8 -*- #http://blog.csdn.net/myhaspl #code:myhaspl@qq.com ...
- Ipsec transport mode and turnnel mode
隧道(tunnel)模式:用户的整个IP数据包被用来计算AH或ESP头,AH或ESP头以及ESP加密的用户数据被封装在一个新的IP数据包中.通常,隧道模式应用在两个安全网关之间的通讯. 传输(t ...
- selenium通过WebDriverWait实现ajax测试
selenium通过WebDriverWait实现ajax测试 AndroidDriver driver = new AndroidDriver(); driver.get("http:// ...
- android最近心得整理
activity中OnAttachedWindow生命周期在OnResume之后,所以对长宽获取在推荐在OnAttachedWindow中进行. onDetachedWindow是在OnDestroy ...
- Linux C语言写的超级简单port扫描器
这个本来曾经也写过的,今天无聊复习下 再写一遍.简单的一塌糊涂,写的不咋地大家见谅哦!有空再加强 嘿嘿! #include <stdio.h> #include <stdlib.h& ...