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 ...
随机推荐
- jsp 格式化日期
第一步,引入工具包: <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %&g ...
- 人为提升服务器CPU、内存、硬盘使用率
一.CPU使用率 vikyd/go-cpu-load: Generate CPU load on Windows/Linux/Mac (github.com) 所有CPU核心负载30%运行10秒钟 . ...
- 【Asp.net】服务器控件<asp:TextBox ></TextBox>如何变为多文本控件
废话不多说,直接上图! 在TextBox上增加TextModel="MultiLine"即可!
- Nginx基础篇
目录 一.nginx基础篇 1.Nginx开源版本安装 2.Nginx的基础配置 3.虚拟主机与域名解析 4.ServerName匹配规则 5.反向代理 6.动静分离 7.location后符号的匹配 ...
- centos NTP时间同步
1.先设置时区 timedatectl set-timezone Asia/Shanghai 2安装ntp服务 yum install chrony 3.修改ntp配置文件的ntp服务器 vi /et ...
- oracle之PGA相关的sql
在上篇文章中初步介绍了关于pga的基础知识,阅读了其他很多关于pga的内容,今天总结一些关于pga的sql和其他知识. 在网上找了相关资料整理而来,可能有点乱,先码上后再整理下. https://bl ...
- 监听 view 初始化时
new ViewTreeObserverRegister().observe(getContentView(), new ViewTreeObserver.OnGlobalLayoutListener ...
- python方法、类方法和静态方法的区别
class A: def f1(): pass def f2(self): pass @classmethod def f3(cls): pass @staticmethod def f4(): pa ...
- 将freeswitch加入CentOS7的systemctl
cd /usr/local/src/freeswitch/build cp freeswitch.service /usr/lib/systemd/system/ cp freeswitch.sysc ...
- 真实世界的算法_pdf
链接:https://pan.baidu.com/s/1OZiDnd2My3FvGIuwO91E7Q 提取码:t88i