1. sessionScope整体的意思是获得存放在session.setAttrbute(key,value)的值即session.getAttribute(key);
<c:choose>
<c:when test="${! empty sessionScope.name}">
欢迎您: ${sessionScope.name}!<a href="user/loginOut.do" style="margin-left: 10px;">退出</a>
</c:when>
<c:otherwise>
<a href="pages/users/login.jsp">登录</a> |
<a href="pages/users/register.jsp">注册</a>
</c:otherwise>
</c:choose>
2.js中var i={}与var i=[]的区别、、????
i={} 对象字面量 等同 i = new Object();
i=[] 数组字面量 等同 i = new Array();
3.
window.location.href="<%=basePath%>test/addItems.do";
window.location.href=getRootPath()+"/test/addItems.do";
一、<%=basePath%>在jsp中使用;
二、getRootPath()是一个js函数,使用需要引入。。一般在js中使用,拿到项目的根路径(包括网址)(就是一个工具)
问:传参数的时候,参数的值中含有“%”,值不能传。
函数内容:
// js获取项目根路径,如: http://localhost:8088/labms_s
function getRootPath() {
// 获取当前网址,如:
// http://localhost:8080/labms_s/navigation/files/sysmanagement/main.jsp?url=sys_equi_number.jsp
var curWwwPath = window.document.location.href;
// 获取主机地址之后的目录,如: /ems/navigation/files/sysmanagement/main.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
// 获取主机地址,"http://localhost:8080"
var localhostPaht = curWwwPath.substring(0, pos);
// 获取带"/"的项目名,如:/jquery
var projectName = pathName
.substring(0, pathName.substr(1).indexOf('/') + 1);
// 返回"/ems/navigation/files/sysmanagement/"
var forwordPath = pathName.substring(0, pathName.length - 8);
// return (localhostPaht + forwordPath);
return (localhostPaht + projectName);
}
4. JavaScript 中的注释
单行//
多行注释以 /* 开始,以 */ 结尾。
例子
/*
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
*/
document.getElementById("myH1").innerHTML="Welcome to my Homepage";
document.getElementById("myP").innerHTML="This is my first paragraph.";
5. 在后台把list转化为json数组,把json数组转化成字符串
@ResponseBody
@RequestMapping("child.do")
public void child(int sid, HttpServletResponse response) {
List<Subject> list = testBiz.getParent(sid);
response.setContentType("text/html; charset=utf-8");
JSONArray array = JSONArray.fromObject(list);
PrintWriter out = null;
try {
out = response.getWriter();
out.print(array);
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
6. @RequestMapping 和 @ResposeBody
一、@RequestMapping:
RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。
@RequestMapping(value = "/aaa")//类级别,可以没有public class myController {
@RequestMapping(value = "/bbb")//方法级别,必须有
public String getMyName() {
return "myReturn";
}
}
二、@responsebody:
@responsebody表示该方法的返回结果直接写入HTTP response body中
一般在异步获取数据时使用,在使用@RequestMapping后,返回值通常解析为跳转路径,加上@responsebody后返回结果不会被解析为跳转路径,而是直接写入HTTP response body中。比如异步获取json数据,加上@responsebody后,会直接返回json数据。
7. jquery文档操作 - append()方法
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。(可包含 HTML 标签)
例子:
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").append(" <b>Hello world!</b>");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>在每个 p 元素的结尾添加内容</button>
</body>
</html>
8. jquery $(“p”).append(“sadas”);(选中所有p元素,把它当做对象来处理)
$(“#s”).append(“adassd”);(“选中id=s的标签,把它当做对象来处理”)
$("select[name='ttypes']").val()(根据元素属性选中元素,把他当做对象来处理)