zoukankan      html  css  js  c++  java
  • GET OR POST

    jsp前端与后端get,post方法api对接 ,转自https://blog.csdn.net/dwenxue/article/details/81586709
    创建HelloWorldController

    package com.controller;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    @Controller
    public class HelloWorldController {
    	//只接受get方式的请求
    	@GetMapping("/testGetMapping")
    	public String testGetMapping(Model model) {
    		model.addAttribute("msg","测试@GetMapping注解");
    		return "success";
    	}
    	//只接受post方式的请求
    	@PostMapping("/testPostMapping")
    	public String testPostMapping(Model model) {
    		model.addAttribute("msg","测试@PostMapping注解");
    		return "success";
    	}
    }
    

    创建index.jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>index</title>
    </head>
    <body>
    	<form action="testGetMapping" method="get">
    		<button>测试@GetMapping注解</button>
    	</form>
    	<br>
    	<form action="testPostMapping" method="post">
    		<button>测试@PostMapping注解</button>
    	</form>
    </body>
    </html>
    

    创建success.jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>success</title>
    </head>
    <body>
    	${requestScope.msg }
    </body>
    </html>
    

    启动Tomcat访问index.jsp

    点击【测试@GetMapping注解】

    点击【测试@PostMapping注解】

  • 相关阅读:
    xmind等工具下载
    remix使用经验积累
    visual studio code下载地址
    以太坊存储类型(memory,storage)及变量存储详解
    remix共享本地文件夹教程
    在remix恢复已部署的合约步骤
    ERC721 相关语法和知识点学习
    用truffle写测试用例
    truffle环境搭建和应用
    jenkins pipeline基础语法与示例
  • 原文地址:https://www.cnblogs.com/shenxiaodou/p/12316297.html
Copyright © 2011-2022 走看看