通过Servlet实现计算器
来源:互联网 发布:女装尺码表参照数据 编辑:程序博客网 时间:2024/05/16 09:43
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ConterServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
ServletContext context = req.getSession().getServletContext();
if(null == context.getAttribute("counter"))
{
context.setAttribute("counter", 1);
}
else
{
int num = (Integer)(context.getAttribute("counter"));
context.setAttribute("counter", num+1);
}
req.getRequestDispatcher("counter.jsp").forward(req, resp);
}
}
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 'counter.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">
</head>
<body>
计数器: <%= application.getAttribute("counter") %>>
</body>
</html>
- 通过Servlet实现计算器
- 通过DELPHI实现计算器功能.
- 通过servlet实现分页
- jsp+servlet实现在线简易计算器
- 通过Servlet实现用户登录
- jsp及servlet分别实现简单的计算器
- ANTLR实现加法计算器(通过AST形式来实现)
- C语言-计算器实现(Dev c++编译通过)
- 通过Struts实现计算器来学习ActionFrom和Action.
- C++语言 通过类模板实现加法计算器
- 使用Python list通过递归实现一个表达式计算器
- 通过servlet实现mvc(drp)
- servlet 实现通过流数据传输下载
- 通过servlet实现ftp下载功能
- 通过ServletContext实现Servlet之间共享数据
- Servlet实现通过getRequestDispatcher().forward页面转发
- java中通过Servlet实现文件下载
- 通过Spring实现servlet的复用
- Rails中文Podcasts【三】
- 网易游戏2010运维工程师笔试题
- github for Windows使用介绍
- SSH超时自动断开问题解决
- 小米2013校园招聘笔试最后一题(朋友圈)
- 通过Servlet实现计算器
- Intent对象的作用和构成
- nodejs库
- UCI数据库使用说明
- z/OS 枚举法获取用户密码
- C++的虚基类,抽象类,虚函数,纯虚函数,virtual
- struts2入门
- android布局1(布局一个始终在右边的button)
- myeclipse8.5调试web项目步骤以及关键点