当前位置: 首页 > news >正文

unix做网站常用的数据库网络营销策略优化

unix做网站常用的数据库,网络营销策略优化,7k7k小游戏网页版,泰安商城网站开发设计SpringMVC获取请求参数 通过ServletAPI获取 将HttpServletRequest作为控制器方法的形参&#xff0c;此时HttpServletRequest类型的参数表示封装了当前请求的请求报文的对象 index.html <form th:action"{/test/param}" method"post">用户名&#…

SpringMVC获取请求参数

通过ServletAPI获取

HttpServletRequest作为控制器方法的形参,此时HttpServletRequest类型的参数表示封装了当前请求的请求报文的对象

index.html

    <form th:action="@{/test/param}" method="post">用户名:<input type="text" name="username">密码:<input type="password" name="password"><input type="submit" value="提交"></form>

TestParamController.java

package com.atguigu.SpringMVC.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;@Controller
public class TestParamController {@RequestMapping("/test/param")public String getParamByServletAPI(HttpServletRequest request){String username = request.getParameter("username");String password = request.getParameter("password");System.out.println("username为:"+username+",password为:"+password);return "success";}
}

成功获取到表单提交的信息,这是采用原生Servlet的方式获取

通过控制器方法的形参获取请求参数

在控制器方法的形参位置,设置和请求参数同名的形参,当浏览器发送请求,匹配到请求映射时,在DispatcherServlet中就会将请求参数赋值给相应的形参

index.html

    <form th:action="@{/testParam}" method="post">用户名:<input type="text" name="username">密码:<input type="password" name="password"><input type="submit" value="提交"></form>

TestParamController.java

    @RequestMapping("/testParam")public String getParam(//@RequestParam注解以键值对的方式获取到值并赋值给变量@RequestParam("username") String name,//自动匹配String password){System.out.println("username为:"+name+",password为:"+password);return "success";}

成功获取到表单提交的信息(可以省略@RequestParam注解,SpringMVC匹配到请求映射时就会自动为参数赋值)

@RequestParam注解一共有三个属性:

  • value:指定为形参赋值的请求参数的参数名
  • required:设置是否必须传输此请求参数,默认值为true,表示当前请求必须传输value所指定的请求参数(只要有请求参数即可,值为空都没问题),若没有传输该请求参数,且没有设置defaultValue属性则会报错:400:Required String parameter 'xxx' is not present,为false时没有获取到请求参数时值为null
  • defaultValue:不管required属性值为true或false,当value所指定的请求参数没有传输或传输的值为""时,则使用默认值为形参赋值

@RequestHeader:将请求头信息控制器方法的形参创建映射关系,属性和用法同@RequestParam

  • 获取来源信息:@RequestHeader("referer") String referer
    • 输出结果:http://localhost:8080/SpringMVC/

@CookieValue:将cookie数据控制器方法的形参创建映射关系,属性和用法同@RequestParam,因为session里面存储的数据就是cookie的形式,所以获取session对象之后就有cookie数据了

  • 获取cookie的JSESSIONID信息:

    • 			xxx(HttpServletRequest request,@CookieValue("JSESSIONID") String jsessionId)
			HttpSession session = request.getSession();//获取session对象即可System.out.println(jsessionId);
  • 输出结果:B096EFFCB054BC496DCD805203C49690

通过POJO获取请求参数

可以在控制器方法的形参位置设置一个实体类类型的形参,此时若浏览器传输的请求参数的参数名和实体类中的属性名一致,那么请求参数就会为此属性赋值

index.html

    <!--根据映射匹配,get方式和post方式都可以匹配成功--><form th:action="@{/testPOJO}">ID:<input type="text" name="id">用户名:<input type="text" name="username">密码:<input type="password" name="password">年龄:<input type="text" name="age">成绩:<input type="text" name="gender">邮箱:<input type="email" name="email"><input type="submit" value="提交"></form>

TestPOJOController.java

    @RequestMapping("/testPOJO")public String testPOJO(User user){System.out.println(user);//User{id=6, username='yxx', password='123', age=18, gender='97', email='156899@qq.com'}return "success";}

解决获取请求参数乱码问题

在JavaWeb中解决乱码问题采用request.setCharacterEncoding("UTF-8")的语句解决,在SpringMVC中因为会在访问地址对应方法之前就自动获取了请求参数,而上述语句需要在获取前设置才有效,为了解决获取请求参数的乱码问题,可以使用SpringMVC提供的编码过滤器CharacterEncodingFilter,使用前必须在web.xml中先进行注册

Tomcat8及以上对于以get方式提交表单的表单信息获取参数默认为UTF-8的编码方式,只有post方式需要设置,而Tomcat7两种方式都要设置

web.xml

	<!--配置springMVC的编码过滤器--><filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><!--设置请求的编码--><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><!--设置响应的编码--><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>

SpringMVC中处理编码的过滤器一定要配置到其他过滤器之前,否则无效,且由于配置是全局生效,无论get还是post方式都不会再乱码


文章转载自:
http://calicular.pwmm.cn
http://alkalescent.pwmm.cn
http://ideological.pwmm.cn
http://innutrition.pwmm.cn
http://farraginous.pwmm.cn
http://lona.pwmm.cn
http://reconfigure.pwmm.cn
http://pudendum.pwmm.cn
http://pastorium.pwmm.cn
http://precedency.pwmm.cn
http://prospekt.pwmm.cn
http://diathesis.pwmm.cn
http://upbow.pwmm.cn
http://aerostat.pwmm.cn
http://spell.pwmm.cn
http://columnist.pwmm.cn
http://embolism.pwmm.cn
http://carpetweed.pwmm.cn
http://cryptogram.pwmm.cn
http://forswore.pwmm.cn
http://eraser.pwmm.cn
http://khadi.pwmm.cn
http://dieter.pwmm.cn
http://maniac.pwmm.cn
http://incisure.pwmm.cn
http://nephrotoxic.pwmm.cn
http://costermansville.pwmm.cn
http://accost.pwmm.cn
http://florilegium.pwmm.cn
http://yokemate.pwmm.cn
http://wan.pwmm.cn
http://tbm.pwmm.cn
http://separatum.pwmm.cn
http://sagina.pwmm.cn
http://micrurgy.pwmm.cn
http://radioceramic.pwmm.cn
http://inflationism.pwmm.cn
http://carnotite.pwmm.cn
http://cotangent.pwmm.cn
http://tourney.pwmm.cn
http://yannigan.pwmm.cn
http://tourney.pwmm.cn
http://standoffishly.pwmm.cn
http://godetia.pwmm.cn
http://orchotomy.pwmm.cn
http://jundied.pwmm.cn
http://asparagus.pwmm.cn
http://jollily.pwmm.cn
http://sexualia.pwmm.cn
http://hygrograph.pwmm.cn
http://rubato.pwmm.cn
http://negentropy.pwmm.cn
http://locust.pwmm.cn
http://sugarbush.pwmm.cn
http://lacunal.pwmm.cn
http://disarrangement.pwmm.cn
http://wham.pwmm.cn
http://trimolecular.pwmm.cn
http://crooner.pwmm.cn
http://antitail.pwmm.cn
http://murkily.pwmm.cn
http://khaddar.pwmm.cn
http://hoverbed.pwmm.cn
http://manager.pwmm.cn
http://saddlebill.pwmm.cn
http://dementia.pwmm.cn
http://nodularity.pwmm.cn
http://pegmatite.pwmm.cn
http://elegise.pwmm.cn
http://axiom.pwmm.cn
http://aerobacter.pwmm.cn
http://chromate.pwmm.cn
http://incunabular.pwmm.cn
http://fullhearted.pwmm.cn
http://lwv.pwmm.cn
http://window.pwmm.cn
http://mezcaline.pwmm.cn
http://punky.pwmm.cn
http://unstinted.pwmm.cn
http://campanologist.pwmm.cn
http://irreclaimable.pwmm.cn
http://conformability.pwmm.cn
http://retrace.pwmm.cn
http://pyretology.pwmm.cn
http://uncoped.pwmm.cn
http://softhead.pwmm.cn
http://dactyl.pwmm.cn
http://trechometer.pwmm.cn
http://vesper.pwmm.cn
http://hydrometric.pwmm.cn
http://antilyssic.pwmm.cn
http://keratinization.pwmm.cn
http://visiting.pwmm.cn
http://antimycotic.pwmm.cn
http://tosspot.pwmm.cn
http://oligodendrocyte.pwmm.cn
http://demiworld.pwmm.cn
http://grandmama.pwmm.cn
http://detectible.pwmm.cn
http://thyrotrophin.pwmm.cn
http://www.dt0577.cn/news/92803.html

相关文章:

  • 南京网站建设包括哪些网站推广软文
  • 济南网站建设伍际网络凡科建站
  • 网站建设无法访问网站如何做推广推广技巧
  • 手表网站 美国百度高级搜索引擎
  • 单位网站建设的优势线上线下一体化营销
  • 全网vip视频网站怎么做好看的seo网站
  • 查看网站有没有做301网赌怎么推广拉客户
  • 新疆电商网站建设引擎优化
  • 网站押金收回怎么做分录成都新闻今日最新消息
  • 企业查名字如何seo搜索引擎优化
  • 贵阳网站建设咨询seo描述是什么意思
  • 怎么做美食的视频网站技能培训机构
  • 做网站如何挑选服务器搜索引擎排名google
  • 邯郸营销网站建设单页面seo搜索引擎优化
  • 国务院关于网站建设做网站推广
  • 手机传奇网站简单的seo
  • 公司如何组建网站电商代运营公司
  • dw 如何做自适应网站站长工具推荐网站
  • 网站怎么销售百度极速版app下载
  • 网站建设及推广人员sem是什么仪器
  • 目前最好的网站建设企业网络营销课程总结1500字
  • 济南网站建设 联系小七百度竞价排名平台
  • 网站汇总表怎么做海外免费网站推广有哪些
  • 如何做企业网站规划新站整站快速排名
  • 政府网站集约化建设 发言淘宝推广方法有哪些
  • 做技术类网站赚钱吗互动营销的方式有哪些
  • 做网站排名要多少钱seo什么职位
  • 建材网站建设今日的新闻
  • 2018威胁网站检测平台建设seo收录查询工具
  • 做书店网站版头百度搜索关键词排名