springMVC中响应的返回值获取方式
package com.hope.controller;
import com.hope.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author newcityman
* @date 2019/11/27 - 20:38
*/
@Controller("userController")
@RequestMapping(path ={"/user"} )
public class UserController {
/**
* 返回值是String
* @param model
* @return
*/
@RequestMapping(path = "/testString")
public String testString(Model model){
System.out.println("testString执行成功");
User user = new User();
user.setUsername("zmy");
user.setPassword("123");
user.setAge(12);
model.addAttribute("user",user);
return "success";
}
/**
* 测试testVoid方法
* @param
* @return
*/
@RequestMapping(path = "/testVoid")
public void testVoid(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("testString执行成功");
//请求转发
// request.getRequestDispatcher("/WEB-INF/pages/success.jsp").forward(request,response);
//重定向(重定向是不能够直接发送请求去访问WEB-INF下的页面的)
// response.sendRedirect(request.getContextPath()+"/index.jsp");
//直接流进行响应
//设置中文乱码
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
response.getWriter().print("hello 张三");
return;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="user/testString">testString</a><br/>
<a href="user/testVoid">testVoid</a>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h3>执行成功</h3>
${user.username}<br/>
${user.age}<br/>
${user.password}<br/>
</body>
</html>
springMVC中响应的返回值获取方式的更多相关文章
- Java多线程和并发(四),线程返回值获取方式和Callable接口
目录 1.主线程等待法 2.使用Thread类的join()阻塞当前线程,等待子线程执行完毕 3.通过Callable接口实现:通过FutureTask Or线程池获取 四.线程返回值获取方式和Cal ...
- SpringMVC中Controller的返回值类型
Controller方法的返回值可以有以下几种: 1.返回ModelAndView 返回ModelAndView时最常见的一种返回结果.需要在方法结束的时候定义一个ModelAndView对象,并对M ...
- SpringMVC中 controller方法返回值
1)ModelAndView @RequestMapping(value="/itemEdit") public ModelAndView itemEdit(){ //创建模型视图 ...
- SpringMvc中函数的返回值是什么?
返回值可以有很多类型,有String, ModelAndView.ModelAndView类把视图和数据都合并的一起的,但一般用String比较好.
- SSM框架之SpringMVC(4)返回值类型及响应数据类型
SpringMVC(4)返回值类型及响应数据类型 1. 返回值分类 1.1. 返回字符串 Controller方法返回字符串可以指定逻辑视图的名称,根据视图解析器为物理视图的地址. @RequestM ...
- spring 基于xml的申明式AspectH中的后置通知的返回值获取
spring 基于xml的申明式AspectH中的后置通知的返回值获取 1. 配置文件 <aop:config> <aop:aspect ref="myAspect&quo ...
- SpringMVC的Controller的返回值与接收的参数
内容参考自博客: http://blog.csdn.net/u011001084/article/details/52846791 http://blog.csdn.net/xuxiaoyinliu/ ...
- shell函数(调用、返回值,返回值获取)
Shell函数返回值,常用的两种方式:return,echo 1) return 语句shell函数的返回值,可以和其他语言的返回值一样,通过return语句返回.示例1: [devadmin@swa ...
- [转]WinExec、ShellExecute和CreateProcess及返回值判断方式
[转]WinExec.ShellExecute和CreateProcess及返回值判断方式 http://www.cnblogs.com/ziwuge/archive/2012/03/12/23924 ...
随机推荐
- airflow redis sentinel
获取master name subscribe __sentinel__:hello mysql plugin table not found mysqld --initialize-insecure ...
- cgdb | 一起边看源码边调试gdb吧
简介 cgdb是一款轻量级的基于gdb的命令行可视化工具,关系大致如下: 尽管gdb本身可以通过layout src的命令显示源码布局,但是其功能还是过于简陋. 使用cgdb并不需要你重新去学习过多额 ...
- Linux——搭建FTP服务
一.FTP基本概念: 1.FTP的作用: 实现文件系统的安全匿名访问:包括上传.下载和查看,可以应用于Windows和Linux系统 2.FTP的工作原理 server与client都支持ftp传输协 ...
- Salesforce Consumer Goods Cloud 浅谈篇二之门店产品促销的配置
本篇参考:https://documentation.b2c.commercecloud.salesforce.com/DOC1/index.jsp?topic=%2Fcom.demandware.d ...
- 【Redis】(1)-- 关系型数据库与非关系型数据库
关系型数据库与非关系型数据库 2019-07-02 16:34:48 by冲冲 1. 关系型数据库 1.1 概念 关系型数据库,是指采用了关系模型来组织数据的数据库.关系模型指的就是二维表格模型, ...
- kibana解决Kibana server is not ready yet问题
找到kbn的config中的xml配置 将es的ip改成真正的ip
- 洛谷 P4497 - [WC2011]拼点游戏(数据结构综合)
题面传送门 神仙 DS. 首先关于第一问可以轻松想到一个 DP,\(dp_{i,j}\) 表示考虑到第 \(i\) 位,这一位奇偶性为 \(j\) 的最大权值,时间复杂度 \(n^2q\),可以拿到 ...
- 【宏组学】如何根据taxid(或taxname)快速获得taxname(或taxid)?
需求 我有一个物种taxonomy ID的list,想获得相应的物种名,不要一个个去NCBI Taxonomy官网查.反之根据物种名list查询对应的taxid. 实现 因为之前没怎么用过,我的第一个 ...
- 31-Longest Common Prefix
Longest Common Prefix My Submissions Difficulty: Easy Write a function to find the longest common pr ...
- cp -拷贝文件出现错误
对于cp -a最主要的用法是在保留原文件属性的前提下复制文件. 如果出现了拷贝文件错误,在文件前面加上-a 即可