如何删除Java servlet中的cookie?
我试过这个:http: //www.jguru.com/faq/view.jsp?EID = 42225
编辑:以下现在成功运作它似乎是以下的组合:
response.setContentType("text/html");
Run Code Online (Sandbox Code Playgroud)
和
cookie.setMaxAge(0);
Run Code Online (Sandbox Code Playgroud)
在我做之前:
//remove single signon cookie if it hasn't been validated yet
response.setContentType("text/html");
Cookie cookie = new Cookie(SSORealm.SSO_COOKIE_NAME, "");
cookie.setDomain(SSORealm.SSO_DOMAIN);
cookie.setMaxAge(-1);
cookie.setPath("/");
cookie.setComment("EXPIRING COOKIE at " + System.currentTimeMillis());
response.addCookie(cookie);
Run Code Online (Sandbox Code Playgroud)
根据文档关闭浏览器时,cookie会过期.
负值表示cookie不会持久存储,并在Web浏览器退出时被删除.零值会导致cookie被删除.
要使Cookie过期的完整工作代码段是:
//remove single signon cookie if it hasn't been validated yet
response.setContentType("text/html");
Cookie cookie = new Cookie(SSORealm.SSO_COOKIE_NAME, "");
cookie.setDomain(SSORealm.SSO_DOMAIN);
cookie.setMaxAge(0);
cookie.setPath("/");
cookie.setComment("EXPIRING COOKIE at " + System.currentTimeMillis());
response.addCookie(cookie);
Run Code Online (Sandbox Code Playgroud) 有谁知道如何在Maven中读取x.properties文件.我知道有一些方法可以使用资源过滤来读取属性文件并从中设置值,但是我想在我的pom.xml中使用以下方法:
<properties file="x.properties">
</properties>
Run Code Online (Sandbox Code Playgroud)
有一些讨论: Maven外部属性
是否有任何库允许我从shell脚本调用JMX MBean方法.我们通过JMX公开了一些操作/管理命令,我们可以让我们的管理员使用JConsole或VisualVM,但有些任务最好留给自动化.在那个自动化中,我们希望能够在运行的服务器上调用JMX MBean方法,最好是从shell脚本调用.
我们有一个多模块maven项目,它使用一个定义buildnumber-maven-plugin的配置文件来增加内部版本号,然后将其检入源代码控制.
如果我在父pom.xml中定义插件,它也会为所有子构建执行.
这是我的父pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webwars</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<properties>
<buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties>
</properties>
<version>1.0-SNAPSHOT</version>
<name>Parent Project</name>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<format>{0, number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>checkin</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}</basedir>
<includes>buildNumber.properties</includes>
<message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message>
<developerConnectionUrl>...</developerConnectionUrl>
</configuration> …
Run Code Online (Sandbox Code Playgroud) 我在做简单的文本处理和打印语句时经常遇到这种情况,我循环一个集合,我想要特殊情况下的最后一个元素(例如,除了最后一个例子,每个普通元素都将以逗号分隔).
是否有一些最佳实践习惯或优雅的形式,不需要复制代码或在if循环中推..
例如,我有一个字符串列表,我想在逗号分隔列表中打印.(虽然解决方案已经假设列表中有2个或更多元素,否则它就像使用条件的更正确的循环一样糟糕).
例如List =("dog","cat","bat")
我想打印"[狗,猫,蝙蝠]"
我提出了两种方法
对于有条件的循环
public static String forLoopConditional(String[] items) {
String itemOutput = "[";
for (int i = 0; i < items.length; i++) {
// Check if we're not at the last element
if (i < (items.length - 1)) {
itemOutput += items[i] + ", ";
} else {
// last element
itemOutput += items[i];
}
}
itemOutput += "]";
return itemOutput;
}
Run Code Online (Sandbox Code Playgroud)做循环启动循环
public static String doWhileLoopPrime(String[] items) {
String itemOutput = "[";
int i …
Run Code Online (Sandbox Code Playgroud)我正在尝试编写一个bash脚本,该脚本会增加给出的版本号
{major}.{minor}.{revision}
Run Code Online (Sandbox Code Playgroud)
例如.
1.2.13
Run Code Online (Sandbox Code Playgroud)
是否有一种很好的方法可以使用像sed或awk这样的东西轻松提取这3个数字,这样我就可以增加{revision}数字并输出完整的版本号字符串.
我正在尝试从iPhone应用程序的本地资源中提供HTML Javascript和CSS内容,而且我在处理onOrientationChange事件和包括外部Javascript时遇到了问题.
我似乎能够正确地链接CSS但不是javascript.我正在尝试使用以下处理onOrientationChange的示例(如何构建iPhone网站),但我正在从我的应用程序的NSBundle mainBundle提供网页.
我尝试将一个javascript函数附加到body.onorientationchange和window.onorientationchange,但是当从本地(或远程)从UIWebView提供时,它都不起作用,但是如果我正在使用iPhone Safari,它就可以工作.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to build an iPhone website</title>
<meta name="author" content="will" />
<meta name="copyright" content="copyright 2008 www.engageinteractive.co.uk" />
<meta name="description" content="Welcome to engege interactive on the iPhone!" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="apple-touch-icon" href="images/template/engage.png"/>
<style type="text/css">
@import url("iphone.css");
</style>
<!--
<script type="text/javascript" src="orientation.js"></script>
-->
<script type="text/javascript">
function updateOrientation(){
try {
var contentType = "show_normal";
switch(window.orientation){
case …
Run Code Online (Sandbox Code Playgroud) 我们有一个使用Hibernate的二级缓存来避免数据库命中的应用程序.
我想知道当一个外部进程如MySQL管理员直接连接修改数据库(更新/插入/删除)时,是否有一些简单的方法可以使Java应用程序的Hibernate二级缓存无效.
我们使用EHCache作为我们的二级缓存实现.
我们混合使用@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)和@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE),并且我们没有在每个实体上使用时间戳启用Optimistic并发控制.
SessionFactory包含管理二级缓存的方法: - 管理缓存
sessionFactory.evict(Cat.class, catId); //evict a particular Cat
sessionFactory.evict(Cat.class); //evict all Cats
sessionFactory.evictCollection("Cat.kittens", catId); //evict a particular collection of kittens
sessionFactory.evictCollection("Cat.kittens"); //evict all kitten collections
Run Code Online (Sandbox Code Playgroud)
但是因为我们使用@Cache注释单个实体类,所以我们没有"可靠"(例如没有手动步骤)将其添加到列表的中心位置.
// Easy to forget to update this to properly evict the class
public static final Class[] cachedEntityClasses = {Cat.class, Dog.class, Monkey.class}
public void clear2ndLevelCache() {
SessionFactory sessionFactory = ... //Retrieve SessionFactory
for (Class entityClass : cachedEntityClasses) {
sessionFactory.evict(entityClass);
}
}
Run Code Online (Sandbox Code Playgroud)
Hibernate的二级缓存没有真正的方法来知道数据库中的实体发生了变化,除非它查询该实体(缓存正在保护您的实体).因此,作为一种解决方案,我们可以简单地调用一些方法来强制二级缓存驱逐一切(再次因为缺乏锁定和并发控制,您可能会因"读取"或更新过时数据而导致进程中的事务风险).
集群/分发Java服务器应用程序的最佳方法是什么?我正在寻找一种方法,允许您通过添加更多应用程序服务器和更多数据库服务器来水平扩展.
"最佳"解决方案允许您为单个节点编写Java应用程序,并希望"隐藏"访问/锁定共享数据的大部分细节.
在分布式环境中,最困难的问题总是归结为多个事务访问共享数据.似乎有两种常见的并发事务方法.
我一直在研究扩展解决方案(以及提供如何扩展的示例的一般应用程序),例如:
Terracotta似乎是最完整的解决方案,因为您可以"轻松"修改现有服务器应用程序以支持扩展(在定义@Root对象和@AutoLockRead/Write方法之后).问题是要真正从分布式应用程序中获得最大的性能,分布式系统的优化实际上并不是一个想法,你必须设计它,知道对象访问可能被网络I/O阻止.
为了正确扩展,似乎总是归结为分区数据和负载平衡事务,例如给定的"执行单元"(cpu core - > thread - >分布式应用程序节点 - > DB主节点)
似乎通过群集使任何应用程序可以正确扩展,您需要能够根据数据访问读/写对事务进行分区.人们提出了哪些解决方案来分发他们的应用程序数据(Oracle,Google BigTable,MySQL,数据仓库),以及一般如何管理分区数据(许多写入主数据库,以及更多读取数据库等).
在扩展数据持久层方面,在将数据划分给许多读者/多个编写者方面,哪种类型的配置最佳扩展(通常我会基于给定用户(或通常是您的任何核心实体)对数据进行分区"root"对象实体)由单个主DB拥有
java concurrency scalability transactions optimistic-locking
我在使用AVAudioPlayer时遇到问题,我想重置一个播放器,如果它正在播放并重新播放.
我试着以下没有运气:
声音播放一次,但第二次我选择按钮停止声音,第三次再次启动声音.
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
[player stop];
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用player.currentTime = 0来表示会重置播放器,这不起作用,我也尝试重置currentTime = 0然后调用不起作用的播放.
//Stop the player and restart it
if (player.playing) {
NSLog(@"Reset sound: %@", selectedSound);
player.currentTime = 0;
[player play];
} else {
NSLog(@"playSound: %@", selectedSound);
[player play];
}
Run Code Online (Sandbox Code Playgroud) java ×5
iphone ×2
maven-2 ×2
transactions ×2
audio ×1
bash ×1
build ×1
concurrency ×1
cookies ×1
core-audio ×1
database ×1
ehcache ×1
hibernate ×1
idioms ×1
jmx ×1
loops ×1
scalability ×1
scripting ×1
sed ×1
servlets ×1
shell ×1
sysadmin ×1
uiwebview ×1
versioning ×1
while-loop ×1