java ee用tomcat_JAVA EE:学习使用tomcat服务器

1 package edu.fjnu.controller;2

3 import java.io.IOException;4 import java.io.PrintWriter;5

6 import javax.servlet.ServletException;7 import javax.servlet.http.HttpServlet;8 import javax.servlet.http.HttpServletRequest;9 import javax.servlet.http.HttpServletResponse;10

11 public class MyCalcServlet extends HttpServlet {12

13 /**14 * Constructor of the object.15 */16 public MyCalcServlet() {17 super();18 }19

20 /**21 * The doGet method of the servlet.

22 *23 * This method is called when a form has its tag value method equals to get.24 *25 * @param request the request send by the client to the server26 * @param response the response send by the server to the client27 * @throws ServletException if an error occurred28 * @throws IOException if an error occurred29 */30 public void doGet(HttpServletRequest request, HttpServletResponse response)31 throws ServletException, IOException {32

33 int begin = Integer.parseInt(request.getParameter("begin"));34 int end = Integer.parseInt(request.getParameter("end"));35

36 //System.out.println("calc sope:"+begin+"-"+end);37

38 long sum = 0L;39 for(int i=begin;i<=end;i++){40 sum += i;41 }42

43 response.setContentType("text/html");44 PrintWriter out= response.getWriter();45 out.println(""-//W3C//DTD HTML 4.01 Transitional//EN\">");46 out.println("");47 out.println("

A Servlet");48 out.println(" ");49 out.print(begin+"+...+"+end+"="+sum);50 out.println(" ");51 out.println("");52 out.flush();53 out.close();54 }55

56 /**57 * The doPost method of the servlet.

58 *59 * This method is called when a form has its tag value method equals to post.60 *61 * @param request the request send by the client to the server62 * @param response the response send by the server to the client63 * @throws ServletException if an error occurred64 * @throws IOException if an error occurred65 */66 public void doPost(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException {68

69 response.setContentType("text/html");70 PrintWriter out = response.getWriter();71 out.println(""-//W3C//DTD HTML 4.01 Transitional//EN\">");72 out.println("");73 out.println("

A Servlet");74 out.println(" ");75 out.print(" This is ");76 out.print(this.getClass());77 out.println(", using the POST method");78 out.println(" ");79 out.println("");80 out.flush();81 out.close();82 }83

84 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值