华为荣耀9和v9的区别v9与荣耀九什么区别

使用ssm框架通过ajax异步提交数据
使用ssm框架通过ajax异步提交数据:最近公司开始一个java开发的erp项目,从新学起的感觉倍爽,各种问题各种遇到,从通过ajax异步提交数据具体实现方法这里开始。
下面就是我通过springM和ajax异步实现数据更新的解决方法。
虽然网上已经有好多的解决的方法,但是一直拿来试用并不好用,所以提供以下自己的方法。
以简易的添加方法为例
在controller中的代码如下
@RequestMapping(&/add&)
@ResponseBody//必须加入的注解
public JSONObject add(ReturnedMoney goodsName,HttpServletRequest request) {
JSONObject json = new JSONObject();
//System.out.println(goodsName.getYear());
this.GoodsNameService.insert(goodsName);
json.put(&msg&, &1&);
}catch(Exception e){
json.put(&msg&, &0&);
e.printStackTrace();
在前段页面中的代码如下
function add() {
var number = $(&#number&).val();
var storeNum = $(&#storeNum&).val();
var date = $(&#date&).val();
var money = $(&#money&).val();
type : &post&,
url : basePath + &returned_money/add&,
//async:false,
&number& : number,
&storeNum& : storeNum,
&date& : date,
&money& : money,
dataType : 'json',
success:function(msg){
if(msg.msg ='1'){
reloadTest();
}else if(msg.msg ='0'){
alert(&添加失败&);温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
who am I??
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
本文转载自demon
&&& & & & & & & 空白较多的7行数据为数据库数据,但遍历后的值中却多出了function....这样的多余的值。& & 原因:& & & & & & & & & 尚不明确。& & 解决:& & & & & & & &将forin改为一般的for循环。
阅读(3719)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'【转载】AJAX中JSON数据的返回处理问题',
blogAbstract:'&& & & & & & AJAX处理复杂数据时,便会使用JSON格式。常用在对数据库的数据查询上。在数据库查询到数据后,便可在处理页面直接将数据转为JSON格式,然后返回。本篇主要讨论:jQuery中,JSON数据在AJAX回调函数中使用,可能出现的3个问题。案例:\t$.ajax({&\t& & & & & & & & & & type:\"post\",&\t& & & & & & & & & & url:\"check.php\",&\t& & & & & & & & & &data:\"findtext=yes&name=\"+$findWhat,',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:5,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'who am I??',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}jquery&ajax返回json数据进行前后台交互实例
利用jquery中的ajax提交数据然后由网站后台来根据我们提交的数据返回json格式的数据,下面我来演示一个实例。
&先我们看演示代码
&代码如下 复制代码
&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
&html xmlns=""&
&meta http-equiv="Content-Type" content="text/
charset=utf-8" /&
&title&Ajax json
test&/title&
&script language="javascript"
src="./jquery-1.7.1.min.js"
/&&/script&
&script language="javascript" src="./ajax_json.js"
/&&/script&
style="font-family:Aline-height:150%"&
href="javascript:getAllUsers();"&获取所有用户信息&/a&
&!-- 用于显示返回结果 --&
id="users"&&/div&
当我们点击 获取所有用户信息在div的id=users中显示
Ajax返回的JSON字符串:
[{"userId":1,"userName":"Raysmond"},{"userId":2,"userName":"u96f7u5efau5764"},{"userId":3,"userName":"Rita"}]
解析出来的结果为:
userId = 1
userName = Raysmond
userId = 2
userName = 雷建坤
userId = 3
userName = Rita
上面代码大家可能看不懂,我们现在来详细介绍
代码如下 复制代码
index.html
&!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
&html xmlns=""&
&meta http-equiv="Content-Type" content="text/
charset=utf-8" /&
&title&Ajax json
test&/title&
&script language="javascript"
src="./jquery-1.7.1.min.js"
/&&/script&
&script language="javascript" src="./ajax_json.js"
/&&/script&
style="font-family:Aline-height:150%"&
&&h1&Ajax利用JSON进行前后台交互&/h1&
href="javascript:getAllUsers();"&获取所有用户信息&/a&
&&!-- 用于显示返回结果
id="users"&&/div&
&/html&ajax_json.js
function getJson(RequestData,URL){
& type:'POST',
& data:RequestData,
& async:false, //为了简便,设置为同步操作
& cache: false,
& success:function(responseData){
&& reJson=responseD
&return reJ
function getAllUsers(){
&var url = "./service.php";
&var request = 'action=get_all_users';
&//从后台获取并解析,由于上面封装ajax采用的是同步返回,
&//所以这样操作能成功获取返回数据
&var json = getJson(request,url);
&var users =& eval_r('('+ json
&var usersHtml =
'&br/&&span
style="color:"&Ajax返回的JSON字符串:&/span&&br/&'
&&& + json +
'&br/&&br/&&span
style="color:"&解析出来的结果为:&/span&&br/&';
i=0;i&users.++i){
& usersHtml += 'userId = ' + users[i].userId +
+ 'userName = ' + users[i].userName +
&//把构造的HTML利用jQuery动态显示到页面
&$('#users').empty().html(usersHtml);
service.php
&//接受请求参数并根据参数选择操作
&if(isset($_POST['action'])&&$_POST['action']!=""){
switch($_POST['action']){
'get_all_users': getAllUsers();
&//处理请求:以JSON格式返回所有用户信息
&function getAllUsers(){
& $users = array(
array("userId"=&1,"userName"=&"Raysmond"),
array("userId"=&2,"userName"=&"雷建坤"),
array("userId"=&3,"userName"=&"Rita")
& echo json_encode($users);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。学习笔记_springmvc返回值、数据写到页面、表单提交、ajax、重定向 - 推酷
学习笔记_springmvc返回值、数据写到页面、表单提交、ajax、重定向
实验是在前一篇文章的项目上做的;
数据写到页面
后台往前台传数据
TestController添加
* 方法的返回值采用ModelAndView, new ModelAndView(&index&, map);,
* 相当于把结果数据放到request里面
* @throws Exception
@RequestMapping(&/toPerson4.do&)
public ModelAndView toPerson4() throws Exception{
Person person = new Person();
person.setName(&jerome&);
person.setAge(22);
person.setAddress(&nanan&);
SimpleDateFormat format = new SimpleDateFormat(&yyyy-MM-dd&);
Date date = format.parse(&&);
person.setBirthday(date);
Map&String,Object& map = new HashMap&String, Object&();
map.put(&p&, person);
return new ModelAndView(&jsp/index&,map);
页面接收:index.jsp
&h5&${p.name }&/h5&
&h5&${p.age }&/h5&
&h5&${p.address }&/h5&
&h5&&fmt:formatDate value=&${p.birthday }& pattern=&yyyy-MM-dd&/&&/h5&
在jsp引入fmt标签库
* 文章包含被禁用的url,无法保存和发布。&
太坑了,这个链接也屏蔽~&
重启tomcat访问:
http://localhost:8080/springmvc-2/test/toPerson4.do
输出信息正确;
另外一种方式:&
* 直接在方法的参数列表中来定义Map,这个Map即使ModelAndView里面的Map
* 由视图解析器统一处理,统一走ModelAndView的接口
* 也不建议使用
* @param map
* @throws Exception
@RequestMapping(&/toPerson5.do&)
public String toPerson5(Map&String,Object& map) throws Exception{
Person person = new Person();
person.setName(&jerome&);
person.setAge(22);
person.setAddress(&nanan&);
SimpleDateFormat format = new SimpleDateFormat(&yyyy-MM-dd&);
Date date = format.parse(&&);
person.setBirthday(date);
map.put(&p&, person);
return &jsp/index&;
重启tomcat访问:
http://localhost:8080/springmvc-2/test/toPerson5.do
输出正确;
建议使用方式:
*在参数列表中直接定义Model,model.addAttribute(&p&, person);
*把参数值放到request类里面去,建议使用
* @param map
* @throws Exception
@RequestMapping(&/toPerson6.do&)
public String toPerson6(Model model) throws Exception {
Person person = new Person();
person.setName(&jerome&);
person.setAge(22);
person.setAddress(&nanan&);
SimpleDateFormat format = new SimpleDateFormat(&yyyy-MM-dd&);
Date date = format.parse(&&);
person.setBirthday(date);
//把参数值放到request类里面去
model.addAttribute(&p&, person);
return &jsp/index&;
重启tomcat访问:
http://localhost:8080/springmvc-2/test/toPerson6.do
输出正确数据;
不需要页面跳转:ajax
后台方法:
在TestController加
* ajax的请求返回值类型应该是void,参数列表里直接定义HttpServletResponse,
* 获得ProntWriter的类,最后可把结果写到页面
* 不建议使用
* @param name
* @param response
@RequestMapping(&/ajax.do&)
public void ajax(String name, HttpServletResponse response) {
String result = &hello & +
response.getWriter().write(result);
} catch (IOException e) {
e.printStackTrace();
前台调用 新建ajax.jsp
&input id=&myButton& type=&button& value=&click&&
Webroot新建js文件夹将jquery拷贝进来;
引进来jquery 和写js脚本:
&script type=&text/javascript&&
$(function(){
$(&#myButton&).click(function(){
url:&test/ajax.do&,
type:&post&,
dataType:&text&,
name:&zhangsan&
success:function(responseText){
alert(responseText);
error:function(){
alert(&system error&);
后台写一个转发:
@RequestMapping(&/toAjax.do&)
public String toAjax() {
return &jsp/ajax&;
重启tomcat 访问&
http://localhost:8080/springmvc-2/test/toAjax.do
Click,弹出hello zhangsan,成功;
以上方法不建议使用,建议使用:
* 直接在参数的列表上定义PrintWriter,out.wrote(result);
* 把结果写到页面,建议使用
* @param name
* @param out
@RequestMapping(&/ajax1.do&)
public void ajax1(String name, PrintWriter out) {
String result=&hello1 &+
out.write(result);
修改ajax.jap页面的,js脚本,跳转的url是
url:&test/ajax1.do&,
重启tomcat 访问 &
http://localhost:8080/springmvc-2/test/toAjax.do
hello1 zhangsan;
拷贝一份index,起名form.jsp
&form action=&test/toPerson7.do& method=&post&&
name:&input name=&name& type=&text&&&br/&
age:&input name=&age& type=&text&&&br/&
address:&input name=&address& type=&text&&&br/&
birthday:&input name=&birthday& type=&text&&&br/&
&input type=&submit&&&br/&
TestController
@RequestMapping(&/toPerson7.do&)
public String toPerson7(Person person) {
System.out.println(person);
return &jsp/index&;
重启tomcat 访问:
http://localhost:8080/springmvc-2/test/toForm.do
提交跳转到
http://localhost:8080/springmvc-2/test/toPerson7.do
控制台输出
Person [name=aa, address=asdf, birthday=Tue Jun 03 00:00:00 CST 2014, age=22]
请求方式的指定:
后台可以指定提交方法,如果前台不是用的同一种提交方式 将报错;
* @RequestMapping(value=&/toPerson7.do&,method=RequestMethod.POST)
* 可以指定请求方式,前台就必须要以它制定好的方式来访问,不然会出现405错误
* @param person
@RequestMapping(value=&/toPerson7.do&,method=RequestMethod.POST)
public String toPerson7(Person person) {
System.out.println(person);
return &jsp/index&;
Form.jap的method修改为get和post测试;
同一个 controller
* 重定向:controller内部重定向,redirect:加上同一个controller中
* 的requesMapping的值
@RequestMapping(&/redirectToForm.do&)
public String redirectToForm() {
return &redirect:toForm.do&;
重启tomcat 访问:
http://localhost:8080/springmvc-2/test/redirectToForm.do&
http://localhost:8080/springmvc-2/test/toForm.do
Controller之间的重定向:
拷贝一份TestController改成TestController1
@Controller
//用来标注当前类是springmvc的控制层的类
@RequestMapping(&/test1&)
//controller的唯一标识或者命名空间
public class TestController1 {
@RequestMapping(&/toForm.do&)
public String toForm() {
return &jsp/form&;
TestController 添加
controller之间的重定向:必须要指定好controller的命名空间再
指定requestMapping的值,redirect:后必须要加/,是从根目录开始,
否则就从当天test找了
@RequestMapping(&/redirectToForm1.do&)
public String redirectToForm1() {
return &redirect:/test1/toForm.do&;
重启tomcat 访问
http://localhost:8080/springmvc-2/test/redirectToForm1.do
http://localhost:8080/springmvc-2/test/toForm.do
jquery-1.6.2.js下载:
/s/1o6nwWP0
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致项目地址:/724888/lightnote_new
用户登陆后点击用户名可跳转到用户信息界面
&c:choose&
&c:when test="${username!=null}"&
&li&&a class="mdl-navigation__link mdl-color-text--pink-400"
href="/lightnote/user/userinfo?username=${username}"&${username}&/a&&/li&
&li&&a class="mdl-navigation__link mdl-color-text--black" href="/lightnote/user/logout"&注销&/a&&/li&
&c:when test="${username == null}"&
&li&&a class="mdl-navigation__link mdl-color-text--pink-400" href="http://localhost:8080/lightnote/index.jsp"&登录&/a&&/li&
&li& &a class="mdl-navigation__link mdl-color-text--pink-400" href="http://localhost:8080/lightnote/register.jsp"&注册&/a&&/li&
&/c:choose&
对应的controller代码
@RequestMapping("/userinfo")
public String userinfo(@Param("username") String username,HttpServletRequest request) {
request.setAttribute("username", username);
return "userinfo";
userinfo.jsp中的js交互部分
&script type="text/javascript"&
$(function(){
type: "GET",
url: &%=basePath%&+"user/getuser?username=${username}",
success: function(data){
var body ="";
var td = "&td&&a href=&%=basePath%&+'user/addLoad'&增加&/a& &a href='${ctx}/user/editLoad?id=${user.id}'&修改&/a&
&a href='${ctx}/user/delete?id=${user.id}'&删除&/a& &/td&"
+ "&td&"+data+"&/td&" ;
body + td + "&/tr&";
$("#tab tbody").append(body);
用户信息显示部分
&table id="tab"&
&th&id&/th&
&th&用户名&/th&
&th&密码&/th&
&th&邮箱&/th&
&th&功能&/th&
&c:forEach items="${userList}"
var="user"&
&td&${user.id}&/td&
&td&${user.username}&/td&
&td&${user.password}&/td&
&td&${user.email}&/td&
&td&&a href="${ctx}/user/addLoad"&增加&/a& &a href="${ctx}/user/editLoad?id=${user.id}"&修改&/a&
&a href="${ctx}/user/delete?id=${user.id}"&删除&/a& &/td&
&/c:forEach&
以上就是今天做的内容了。
阅读(...) 评论()}

我要回帖

更多关于 华为荣耀9和v9的区别 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信