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);
        }
    
    }
  • 相关阅读:
    Android开发之Toast的快去替换
    Android开发之Fragment的替换显示反复创建问题
    Android开发之多渠道打包
    Android开发之让其他软件调用自己播放器
    Android开发之的到屏幕的宽和高
    Android开发之视频播放调用setVideoPath()方法
    [luogu4931]情侣?给我烧了!
    CF449D Jzzhu and Numbers
    [PKUWC2018]猎人杀
    [BZOJ3028]食物
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/7402309.html
Copyright © 2011-2022 走看看