1、如何在登陆之后将登录用户信息存入session?
//将用户信息存入session
request.getSession().setAttribute("user","你要存入的信息");
2、如何在用户退出之后销毁session?
// 销毁session
request.getSession().invalidate();
3、request.getContextPath()获取的是什么?
获取的是项目的虚拟目录,比如全部的url为http://localhost:80/travel
。则下列程序即代表 /travel/login.html
request.getContextPath()+"/login.html"
4、Java中substring的使用方法?
endIndex可不写。
public String substring(int beginIndex, int endIndex)
5、Java中父类如何调用子类的方法?
methodName为父类要调用子类的方法名称。this指的是子类。此处只能调用子类中公开的方法。
//获取方法对象Method
Method method = this.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
//执行方法
method.invoke(this,req,resp);
若方法私有,则需要使用getDeclaredMethod()
方法,还需要在执行该方法之前加上暴力反射的语句,即method.setAccessible(true);
//获取方法对象Method
// getMethod(要获取的方法名称,按声明顺序标识该方法形参类型)
Method method = this.getClass().getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
//执行方法
//暴力反射
method.setAccessible(true);
method.invoke(this,req,resp);
6、Java中final的含义?
final可以理解为最终的,例如在定义变量的时候加入final修饰,则表示这个变量只有在定义的时候初始化一次,以后不能再做初始化操作。
7、Java中字符流和字节流的区别?
简单点:
字节->解码->字符。
复杂点:
若干字节->选择某种解码方式->解码->索引字符集->映射到一个字符。
知乎中有人已经回答的非常好了,下面上链接!
点我
8、页面之间传递值?
在js中location.search
返回的数据是url中?之后的字符串。
//url = http://localhost/travel/route_list.html?cid=2
//location.search;取到的字符串为?cid=2
$(function () {
var search = location.search;
//alert(search)
//取具体的数值
var cid = search.split("=")[1];
//alert(cid);
});