在Spring中通过EasyUI的dialog创建登录界面
来源:互联网 发布:js date获取日期 编辑:程序博客网 时间:2024/05/01 22:23
准备工作
- EasyUI相关文件都放在WebContent下
- 将一些必要的Link ,script统一放在一个jsp中,给其他jsp来include
java<script type="text/javascript" src="${pageContext.request.contextPath}/EasyUI/jquery.min.js"></script><script type="text/javascript" src="${pageContext.request.contextPath}/EasyUI/jquery.easyui.min.js"></script><link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/EasyUI/themes/default/easyui.css"><link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/EasyUI/themes/icon.css"><script type="text/javascript" src="${pageContext.request.contextPath}/EasyUI/locale/easyui-lang-zh_CN.js"></script>
后台需要的Util
JSONUtils
将java类转为json数据格式
javapublic abstract class JSONUtils { private static ObjectMapper objectMapper = new ObjectMapper(); static { // 设置日期格式化 objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); // 设置null不序列化 objectMapper.setSerializationInclusion(Include.NON_NULL); } private JSONUtils() { } public static void writeValue(OutputStream out, Object value) { try { objectMapper.writeValue(out, value); } catch (Exception e) { throw new RuntimeException(e.toString(), e); } } public static void writeValue(Writer w, Object value) { try { objectMapper.writeValue(w, value); } catch (Exception e) { throw new RuntimeException(e.toString(), e); } } public static String writeValueAsString(Object arg0) { try { return objectMapper.writeValueAsString(arg0); } catch (Exception e) { throw new RuntimeException(e.toString(), e); } }}
HTMLUtils
将json数据通过response中的writer流输出,返回给Ajax
javapublic class HTMLUtils { public static void writeJosn(HttpServletResponse response,String jsonStr){ try { response.setContentType("text/html"); response.setHeader("Pragma", "No-cache");//设置页面不缓存 response.setHeader("Cache-Control", "no-cache"); response.setCharacterEncoding("UTF-8"); PrintWriter out= response.getWriter(); //获取流 out.print(jsonStr); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }}
前台
java<jsp:include page="/include/include.jsp"/><script type="text/javascript">$(function(){ $("#dig").dialog({ title:"login", modal:true, //是否将窗体显示为模式化窗口 collapsible:true, //是否显示可折叠按钮 minimizable:true, //是否显示最小化按钮 buttons:[{ text:"login", handler:function(){ $.ajax({ url:"<%=request.getContextPath()%>/login.do", type:"post", data:$("#loginForm").serialize(), dataType:"json", success:function(data){ alert("success"+data.msg); if(data.msg=="登录成功"){ $("#dig").dialog("close"); } }, error:function(data){ alert("error"+data.msg); } }) } }] });})</script><body> <div id="dig" style="width:320px;height:180px"> <form id="loginForm"> <table> <tr> <td>用户名:</td><td><input type="text" name="username"></td> </tr> <tr> <td>密码:</td><td><input type="password" name="pwd"></td> </tr> </table> </form> </div></body>
后台
java@Controllerpublic class TestHello { @RequestMapping("/login") public void login(String username,String pwd, HttpServletResponse response){ System.out.println(username); System.out.println(pwd); Map<String,String> map = new HashMap<String,String>(); map.put("msg","登录成功"); String json = JSONUtils.writeValueAsString(map); //map对象转为json对象 HTMLUtils.writeJosn(response, json); }}
0 0
- 在Spring中通过EasyUI的dialog创建登录界面
- jquery-easyui中创建Dialog
- 简单的EasyUI登录界面
- easyUI 创建Dialog对话框
- 关于解决easyui中注销登录跳出tab,跳不到登录界面的解决方法
- 在一个uiViewController中加载一个通过xib创建的uiView,结果界面不正确
- 纯easyui简单的后台登录界面
- Easyui 中dialog小的demo
- EasyUI 通过Class设置Dialog
- easyUI 通过JS显示Dialog
- easyUI 通过JS显示Dialog
- 在独立的环境中通过使用基于 Java 的配置创建和使用Spring 容器
- 解决select2 在easyui dialog中不显示下拉列表的问题
- 如何在需要登录的界面中使用(需要登录的界面)
- easyui动态创建一个dialog
- EasyUI 动态创建对话框Dialog
- EasyUI 关于 panel,window,dialog 通过href加载页面,页面中引用的js不执行的解决方案
- Activity中Dialog的创建
- 狂刷Android范例之4:用代码安装卸载app
- 25题~~字符串中找数字串
- Gridview求和,求平均数,非常简单实用
- 一个小型字符串工具类MString
- 缓存原理解析
- 在Spring中通过EasyUI的dialog创建登录界面
- Mike and Feet(CF 547B)
- 第三章 第四十四题
- uva 11552 Fewest Flops 线性dp
- iOS GCD 之dispatch_group方面的开发
- ThinkPHP 3.2.3 学习(1)
- 汇编语言基础3
- Qt Object模型及其线程和事件处理
- Java Web----EL(表达式语言)详解