关于jq $.session.get('key')的问题

qq228373418 2017-11-22 04:44:54
我在servlet里面

request.getSession.setAttribute("User",User);//User 为实体类

然后在jsp页面
<script src="<%=basePath%>static/js/jquerySession.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var v = $.session.get('User');
console.log(v);
console.log(v.name);
console.log(v.getName());
});
结果是
v 是 undefined
v.name 报错 Uncaught TypeError: Cannot read property 'v.name' of undefined
v.getName() 也报错

请问一下如何解决呢,如何把 v 转换成 User 类型呢,谢谢大家了
...全文
304 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
__san_niu_m 2017-11-22
  • 打赏
  • 举报
回复
直接用el表达式${User.name},js中也可以这样取
qq228373418 2017-11-22
  • 打赏
  • 举报
回复
引用 1 楼 zhang_kang_user 的回复:
你是不是不应该$.session.get('User');这样取值啊,你应该,得到的是request的session,不是jquery的session啊,,你试试el表达式这样<%=request.getSession().getAttribute('User')>
使用el表达式是可以,但是如果这样取的到的话,就很简单很方便了
zk_Kang 2017-11-22
  • 打赏
  • 举报
回复
你是不是不应该$.session.get('User');这样取值啊,你应该,得到的是request的session,不是jquery的session啊,,你试试el表达式这样<%=request.getSession().getAttribute('User')>
Practical instruction on using JavaScript Object Notation (JSON) with MySQL This hands-on guide teaches, step by step, how to use JavaScript Object Notation (JSON) with MySQL. Written by a MySQL Community Manager for Oracle, MySQL and JSON: A Practical Programming Guide shows how to quickly get started using JSON with MySQL and clearly explains the latest tools and functions. All content is based on the author’s years of interaction with MySQL professionals. Throughout, real-world examples and sample code guide you through the syntax and application of each method. You will get in-depth coverage of programming with the MySQL Document Store. •See how JavaScript Object Notation (JSON) works with MySQL •Use JSON as string data and JSON as a data type •Find the path, load data, and handle searches with REGEX •Work with JSON and non-JSON output •Build virtual generated columns and stored generated columns •Generate complex geometries using GeoJSON •Convert and manage data with JSON functions •Access JSON data, collections, and tables through MySQL Document Store 1 Introduction JSON MySQL The Example Database How to Use This Book 2 JSON as String Data vs. JSON as a Data Type JSON String Data The JSON Data Type 3 Finding the Path Examining the world_x Data Seeing the Keys Path Digging Deeper 4 Finding and Getting Data All Keys Searching for a Key Searching for a Path Searching for a Value 5 Changing Data Using Arrays Appending Arrays Inserting into an Array Using TRUNCATE Before Adding New Data Using JSON_INSERT Using JSON_REPLACE JSON_REMOVE JSON_SET JSON_UNQUOTE The Three JSON_MERGE Functions JSON_MERGE JSON_MERGE_PRESERVE JSON_DEPTH JSON_LENGTH JSON_TYPE JSON_VALID JSON_STORAGE_SIZE JSON_STORAGE_FREE 6 JSON and Non-JSON Output JSON-Formatted Data JSON_OBJECT JSON_ARRAY Casting Non-JSON Output Missing Data Nested Data 7 Generated Columns Using Generated Columns Columns Generated from JSON Generated Columns: Common Errors 8 GeoJSON ST_GeomFromGeoJSON ST_AsGeoJSON 9 PHP’s JSON Functions JSON_DECODE JSON_ENCODE 10 Loading JSON Data From Download to Database Step 1: Examine the Data Step 2: Create the Table Step 3: Load the Data Using a Wrapper Step 4: Double-Check the Data jq: JSON CLI Parser With No Arguments Select Certain Fields The Restaurant Collection 11 The MySQL Document Store The X DevAPI mysqlsh Connections Session Types Collections and Documents CRUD: Create, Replace, Update, Delete Filtering Find Sorting Binding Indexing Collections Dropping a Collection 12 Programming with the MySQL Document Store Programming Examples Python Example Node.JS Example PHP Example Traditional SQL vs. MySQL Document Store The MySQL Shell and JavaScript Relational Tables Both Relational and Document Document as Relational A Additional Resources Index

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧