我明白之间的差别request.getSession(true)和request.getSession(false).但是,request.getSession()与request.getSession(true)看起来非常相似!
两者都"返回与此请求关联的当前会话",但不同之处在于:
request.getSession():"或者如果请求没有会话,则创建一个会话"
request.getSession(true):"如果没有当前会话,则返回新会话 "
我不明白它们之间的区别,是否(如果不存在)它们创建一个新会话但第一个不返回它但第二个会返回它?
资料来源:http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html
编辑:
有人将我的问题标记/标记为重复,即使它不是.我会解释原因.
我已经明确要求request.getSession()&request.getSession(true)之间的区别request.getSession(true)&request.getSession(false)!我再次明确地说过,我已经理解了b/w ..(true)&的不同之处..(false).
这个问题被链接为可能重复的关于差异的问题b/w ..(true)&..(false)而不是..(true)&..()
我正在尝试从select语句返回一个值.它只有一个值,因为我返回的值来自主键列.
SQL语句是 SELECT itemNo FROM item WHERE itemName = 'astringvalue';
我获取值的方法如下所示:
private String viewValue(Connection con, String command) throws SQLException
{
String value = null;
Statement stmt = null;
try
{
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(command);
while (rs.next())
value = rs.toString();
}
catch (SQLException e )
{
e.printStackTrace();
}
finally
{
if (stmt !=
null) { stmt.close(); }
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
我也有一个getConnection()方法.
这是我用来调用viewValue方法的方法:
if((action.getSource() == btnSave) ||(action.getSource() == btnSavePrint) )
{
String findItemNoCommand = …Run Code Online (Sandbox Code Playgroud)