MVC内置函数
----HTML页
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="/Dome/PostDate" method="post">
<input type="text" name="loginname" />
<button>提交</button>
</form>
<form action="/Dome/FileDate" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<button>提交</button>
</form>
<form action="/Dome/SessionDate" method="post">
<input type="text" name="user" />
<button>提交</button>
</form>
</body>
</html>
----控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace 项目.Controllers
{
public class DomeController : Controller
{
// GET: Dome
public ActionResult Index()
{
//内置对象 Request Response Session Cooking Application Server
// 请求 响应 会话 客户端数据 当前网站对象 服务器对象
//Request 服务器接收客户端数据
//Request.QueryString get 请求!
//Request.Form post 请求!
//request.MapPath()作用是将虚拟路径转化为物理路径
// Request.Files["file"] 获取的是POSt请求的文件,俗称文件上传
//headers
return Content($"{Request.QueryString["name"]}-{Request.QueryString["age"]}");
}
public ActionResult PostDate()
{
return Content(Request.Form["loginname"]);
}
public ActionResult FileDate()
{
//saveas 方法需要物理路径
//request.MapPath()作用是将虚拟路径转化为物理路径
Request.Files["file"].SaveAs(filename: Request.MapPath("~/uploads/" + Request.Files["file"].FileName));
return Content("ok");
}
public ActionResult ReqponseDate() //响应是服务器给客户端
{
// Response.Write 向客户输出内容
// Response.Redirect 重定向
//Response.Write(s:"hello word");
return Content("");
}
public ActionResult RequestHeader()
{
Request.Headers["hollow"] = "world";
return Content(Request.Headers["token"]); //请求头
}
public ActionResult SessionDate() //所有人自己的存储空间
{
//Sission 会话,数据保存在服务器中(一般用来存储少量重要数据(用户名))
//Sission 是一个键值对
//Session 的存活时间为20分钟
//Session 销毁 Abandon/Clear
Session["user"] = Request.Form["user"];
return Content("会话中使用的数据是"+Session["user"]);
}
public ActionResult GetSession()
{
return Content("当前会话的数据是"+Session["user"]);
}
public ActionResult ClearSession()
{
Session.Clear(); //清除Sission
Session.Abandon(); //销毁Sission
return Content("Sission已经清除");
}
//Cookie 客户端输出的数据一概认为是不安全的数据
public ActionResult CookieSave()
{
//时效性
Response.Cookies.Add(new HttpCookie(name: "token")//服务器告诉客户端cookie需要保存7天
{
Value = "asdfasdfasd",
Expires = DateTime.Now.AddDays(7)
});
return Content("ok");
}
public ActionResult CookieGet()
{
return Content(Request.Cookies["token"].Value); //客户端请求获取到cookie的值
}
public ActionResult CookieClear()
{
//清除cookie 值,使用过期的方式
Response.Cookies.Add(new HttpCookie(name: "token")
{
Expires = DateTime.Now.AddDays(-1)
});
return Content("OK");
}
public ActionResult ApplicationDate() // Application 整个服务器共用存
{
HttpContext.Application["user"] = "adsfasdf";
return Content("");
}
public ActionResult ApplicationGet() //Application 整个服务器共用 取
{
HttpContext.Application["user"] = "adsfasdf";
return Content(HttpContext.Application["user"].ToString());
}
public ActionResult ServerDate() //服务器对象的应用
{
// Server.Transfer 路径不变,内容变了,但是只能转发当前网址内
// Server.MapPath(); 虚拟路径转化为物理路径
// Response.Redirect 用于重定向可定向任意路径
Server.Transfer(path:"`/~~~");
return Content("辛苦了");
}
}
}
- JSP的执行原理、JSP的内置对象、四大作用域解析、MVC模式理解>从零开始学JAVA系列
目录 JSP的执行原理.JSP的内置对象.四大作用域解析.MVC模式理解 JSP的执行原理 这里拿一个小例子来解析JSP是如何被访问到的 首先将该项目部署到tomcat,并且通过tomcat启动 通过 ...
- [.Net Core] 简单使用 Mvc 内置的 Ioc(续)
简单使用 Mvc 内置的 Ioc(续) 本文基于 .NET Core 2.0. 上一章<[.Net Core] 简单使用 Mvc 内置的 Ioc>已经对日常 Mvc 中的 Ioc 的简单用 ...
- JSP运行过程 JSP脚本 静态动态包含 jsp指令 jsp内置对象jsp四大作用域 jsp动作元素 EL表达式 JSTL 设计模式 JSP开发模式 EL内置对象
Day38 JSP JSP的运行过程具体如下: (1)客户端发出请求,请求访问JSP文件. (2)JSP容器先将JSP文件转换成一个Java源文件(Java Servlet源程序),在转换过程中,如果 ...
- MVC路由 路由的三种扩展 替换MVC内置的Handler
Global.asax 是 程序入口文件 路由配置 为什么localhost:8088/Home/Index/1 能返问到我们写的 会去掉前缀跟端口号 变成Home/Index/1 用这个跟路由 ...
- SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.了解SpringBoot的基本概念 2.具体内容 在之前所建立的 SpringBoot 项目只是根据官方文档实现的一个基础程 ...
- Asp.Net六大内置对象
前面学习mvc管道处理模型的时候,我们晓的HttpContext是贯穿全文的一个对象,在HttpRuntime产生,现在我们所谓的Asp.Net六大内置对象,其实就是HttpContext的属性.具体 ...
- Spring,SpringMVC,MyBatis,Hibernate,Servlet的生命周期,jsp有哪些内置对象,Tomcat,Cookie和Session的作用以及区别,oracle,MYSQL等面试题总结
1. 什么是Spring,谈谈你对Spring的理解 Spring是我们JAVA开发人员在搭建后台时选用的一个轻量级的开源框架,Spring框架目前也是功能丰富,十分优秀企业级采用最多的一个框架. S ...
- java web学习总结(二十五) -------------------JSP中的九个内置对象
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- javaScript的内置对象
javaScript 有11种内置对象: Array . String .Date .Math . Boolean .Number . Function .Global .Error . RegExp ...
- ASP.NET的六大内置对象
ASP.NET 六大内置对象(System.Web.UI.Page类): 1.Response 2.Request 3.Server 4.Application 5.Session 6.Cooki R ...
随机推荐
- 使用NSIS打包软件
平台和所需软件 平台: Windows 使用软件: NSIS https://nsis.sourceforge.io/Download HM NIS Edit https://sourceforge. ...
- git远程分支回退到某个版本
1.找到要回退的版本号(右击项目--> Git --> Show History -->选中要回退的版本-->Copy Revision Number): 2.打开idea的T ...
- (0619) wavedrom 画时序图---链接
https://www.cnblogs.com/jackzhang001/p/15879207.html
- Visual Studio 快速生成构造函数
生成构造函数快速操作 - Visual Studio (Windows) | Microsoft Learn 键盘 按 (Ctrl+.) 触发"快速操作和重构"菜单. 鼠标 右键单 ...
- Postman中添加多个Cookie
在接口测试中,很多接口都是需要登录后才能获取到数据的.如何标识登录状态呢?有些app用token,有些app用Cookie.通过Fiddler抓包看到,我涯使用的是Cookie的方式,而且是有多个Co ...
- 开启Runjar , 使用beeline连接hive
要先开启hadoop服务 进入root用户hive目录 输入bin/hiveservices.sh stop 停止 输入bin/hiveservices.sh start ...
- Delphi 从字符串中提取数字
function GetNumberFromStr(strIn: string; sFlag: string): string; var i: Integer; tempStr: string; be ...
- IMX6Ull驱动
mount -t nfs -o nolock,vers=3 192.168.1.117:/home/book/nfs_rootfs /mnt cat /proc/sys/kernel/printk e ...
- pyton3 字典排序
1. 字典排序 d={'a':1,'c':3,'b':2} d1={k:d[k] for k in sorted(d)}
- centos下安装部署nginx
1.在安装Nginx之前,要确保已经安装了需要的软件:gcc.pcre-devel.zlib-devel.openssl-devel.如果没有安装,执行下面命令. yum -y install gcc ...