我有以下页面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://omnifaces.org/ui"
xmlns:thehub="http://java.sun.com/jsf/composite/components/thehub"
template="/templates/masterTemplate.xhtml">
<f:metadata>
<f:viewParam
id="returnToViewParam"
name="returnTo"
value="#{loginMB.returnTo}"
required="true" />
<f:viewParam
id="oauth_verifierViewParam"
name="oauth_verifier"
value="#{loginMB.oauth_verifier}" />
<f:viewParam
id="oauth_tokenViewParam"
name="oauth_token"
value="#{loginMB.oauth_token}" />
<f:event
type="preRenderView"
listener="#{loginMB.preRenderView()}" />
</f:metadata>
<ui:define name="body">
<o:form
id="loginForm"
includeViewParams="true">
<div class="form-vertical well">
<h4>New Users</h4>
<h5>
<h:link outcome="signup">Click here to create an account</h:link>
</h5>
<hr />
<h4>Existing Users</h4>
<h:commandButton
id="googleLoginCommandLink"
styleClass="btn"
action="#{loginMB.redirect()}"
value="Google">
<f:param
name="returnTo"
value="#{param.returnTo}" />
</h:commandButton>
<div class="clearfix"></div>
</div>
</o:form>
</ui:define> …Run Code Online (Sandbox Code Playgroud) 说你有这个代码:
private Object lockObject = new Object();
private Integer myValue = new Integer(0);
public void update(){
synchronized(lockObject){
System.out.println(myValue);
myValue++;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,myValue既不是synchronized开启也不是标记volatile.但是,改变它的唯一方法是使用该update()方法.DZone对核心java并发性的refcard说,所有线程都可以看到同步块中字段的更新.我不确定这是指仅同步对象(lockObject)还是任何字段(如myValue).
任何人都可以详细说明这个吗?谢谢!
PrettyFaces是一个简单的URL重写引擎.各种搜索引擎优化都是可能的,这真的很容易.我有一个小问题:(
使用漂亮的面孔,我有这个重写规则:
<url-mapping id="blogEntry">
<pattern value="/blog/#{shortUrl}" />
<view-id value="/blogEntry.jsf" />
</url-mapping>
Run Code Online (Sandbox Code Playgroud)
所以URL栏看起来像:
http://host.com/blog/first-post
Run Code Online (Sandbox Code Playgroud)
并且重写规则将请求内部映射到:
http://host.com/blogEntry?shortUrl=first-post
Run Code Online (Sandbox Code Playgroud)
我正在实现OpenID,这意味着我需要为OpenID提供程序提供一个返回URL.但是,当我执行以下操作时:
originalUrl = Faces.getRequest().getRequestURL().toString()
Run Code Online (Sandbox Code Playgroud)
我明白了:
http://host.com/blogEntry.jsf
Run Code Online (Sandbox Code Playgroud)
getQueryString()返回一个空字符串
任何人都知道如何获得purty URL:http://host.com/blog/first-post或至少是查询字符串shortUrl=first-post
试图找出我是在做错什么,还是这是Maven Checkstyle插件中的错误。如果我mvn checkstyle:check明白了:
jonathanfisher@odin ~/dev/snapjms/snapjms $ mvn checkstyle:check
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building snapjms 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-checkstyle-plugin:2.17:check (default-cli) @ snapjms ---
[INFO] There is 1 error reported by Checkstyle 6.11.2 with /Users/jonathanfisher/dev/snapjms/snapjms/target/checkstyle-rules.xml ruleset.
[ERROR] src/main/java/org/xxx/xxx/snapjms/jms/factories/UnsupportedPayloadException.java:[8] (sizes) LineLength: Line is longer than 135 characters (found 144).
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.411 s
[INFO] Finished at: 2016-06-16T15:33:58-05:00
[INFO] Final Memory: 17M/371M
Run Code Online (Sandbox Code Playgroud)
如果我确实mvn checkstyle:checkstyle注意到它如何翻转到sun_checks.xml …
为什么Java String.toCharArray()和new String(char[])方法不接受字符集编码?
如果您正在使用byte[],可以选择使用String.getBytes(charset)和指定字符集new String(byte[], charset).
我想知道是否有一些关于char[]我不理解的字符串编码.Javadocs中没有任何特别的东西可以解释这种差异.
我正在使用Java代理和Javassist为一些JDK类添加一些日志记录.本质上,当系统加载一些TLS类时,Javassist将为它们添加一些额外的字节码,以帮助我调试一些连接问题.
这是问题,因为这个类包含在代理jar中:
package com.something.myagent;
public class MyAgentPrinter {
public static final void sayHello() {
System.out.println("Hello!");
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代理的转换方法中,假设我试图使用javassist调用该类:
// this is only called for sun.security.ssl.Handshaker
ClassPool cp = getClassPool(classfileBuffer, className);
CtClass cc = cp.get(className);
CtMethod declaredMethod = cc.getDeclaredMethod("calculateKeys");
declaredMethod.insertAfter("com.something.myagent.MyAgentPrinter.sayHello();");
cc.freeze();
return cc.toBytecode();
Run Code Online (Sandbox Code Playgroud)
你认为这会有效,但我得到了这个:
java.lang.NoClassDefFoundError: com/something/myagent/MyAgentPrinter
at sun.security.ssl.Handshaker.printLogLine(Handshaker.java)
at sun.security.ssl.Handshaker.calculateKeys(Handshaker.java:1160)
at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:292)
Run Code Online (Sandbox Code Playgroud)
有没有办法将该类[ MyAgentPrinter] 添加到应用程序的类路径?
考虑以下构建配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${surefireArgLine}</argLine>
<parallel>all</parallel>
<threadCount>2</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>${failsafeArgLine}</argLine>
<parallel>classes</parallel>
<threadCount>2</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-ut.exec</dataFile>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
和报告配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<id>JaCoCo-UnitTest</id>
<reports>
<report>report</report>
</reports>
<configuration>
<dataFile>${project.build.directory}/jacoco-ut.exec</dataFile>
</configuration>
</reportSet> …Run Code Online (Sandbox Code Playgroud) 我在主类中创建了10个相同的线程(仅通过1到10的主键区分).在每个线程中,我需要读取前一个线程中的字段,即在线程5中,我需要在线程4中读取该字段.问题是我该怎么做?
public class Player extends Thread {
private Integer playerNumber;
public char lastDigit;
public Player(Integer playerNumber) {
super();
this.playerNumber = playerNumber;
}
public synchronized char getDigit(){
return this.lastDigit;
}
public synchronized void setDigit(char digit){
massage += digit;
this.lastDigit = digit;
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run(){
}
Run Code Online (Sandbox Code Playgroud)
我需要读取lastDigit字段.
提前致谢 :)
假设你有一个带有视图参数的页面,比如 /widgets?widgetId=1
<f:metadata>
<f:viewParam
name="widgetId"
value="#{widgetIdMB.widgetId}"
converter="#{widgetIDConverter}" />
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
所以,少说你的转换器抛出一个ConverterException,因为有人试图导航到 /widgets?widgetId=1000000,这在数据库中是不存在的.有没有办法在发生这种情况时将此人发送到404页面?
编辑:
我使用转换器来转换值.如果无法在数据库中查找该值,则转换器将返回null,而不是抛出ConverterException.
然后我使用验证器.验证器将抛出validationexception,但在调用omnifaces实用程序类之后不会:Faces.responseSendError(404, "Not Found");
这似乎是关注点分离的最佳实现.
java ×7
jsf ×2
jsf-2 ×2
maven ×2
bytecode ×1
checkstyle ×1
classpath ×1
concurrency ×1
converter ×1
encoding ×1
facelets ×1
jacoco ×1
java-ee ×1
javaagents ×1
javassist ×1
omnifaces ×1
prettyfaces ×1
string ×1
testing ×1