zoukankan      html  css  js  c++  java
  • servlet+jsp结合完成加法运算

    <%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="/day_11/Aservlet" method="post">
        数据A:<input type="text" name="data1"/><br/>
        数据B:<input type="text" name="data2"/><br/>
        <input type="submit" value="提交"/><hr/>
    </form>
    </body>
    </html>
    <%@ page language="java" import="java.util.*"contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!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=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <% 
    Integer c = (Integer)request.getAttribute("aaa");
    %>
    <%=c %>
    </body>
    </html>
    package cn.code.jia;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class Aservlet
     */
    @WebServlet("/Aservlet")
    public class Aservlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public Aservlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            String s1 = request.getParameter("data1");
            String s2 = request.getParameter("data2");
            int a =Integer.parseInt(s1);
            int b =Integer.parseInt(s2);
            int sum=a+b;
            request.setAttribute("aaa", sum);
            request.getRequestDispatcher("/jsps/result.jsp").forward(request, response);
        }
    
    }
  • 相关阅读:
    《挑战程序设计竞赛》 一二章部分代码题解
    动态规划之矩阵连乘和POJ 1651
    关于图片的重绘,从而进行压缩
    iOS开发:读取pdf文件
    如何改变tableview的section的颜色
    端口的作用
    Mac 下,配置SVN
    cocoaPods 的安装和使用
    关于如何调用苹果自带的地图APP
    关于 HTTP 请求头的内容
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/7402309.html
Copyright © 2011-2022 走看看