我目前正在编写一个法国网站.有一个计划页面,侧面的链接可用于加载另一天的计划.
这是我用来做这个的JS:
<script type="text/javascript">
function load(y) {
$.get(y,function(d) {
$("#replace").html(d);
mod();
});
}
function mod() {
$("#dates a").click(function() {
y = $(this).attr("href");
load(y);
return false;
});
}
mod();
</script>
Run Code Online (Sandbox Code Playgroud)
实际的AJAX就像一个魅力.我的问题在于对请求的响应.
因为它是法国网站,所以有许多重音字母.出于这个原因,我正在使用ISO-8859-15字符集.但是,在对我的AJAX请求的响应中,重音变成了?因为字符编码似乎被改回到UTF-8.
我该如何避免这种情况?我已经尝试在请求的文档顶部添加一些PHP来设置字符集:
<?php header('Content-Type: text/html; charset=ISO-8859-15'); ?>
Run Code Online (Sandbox Code Playgroud)
但这似乎也不起作用.有什么想法吗?
此外,虽然你们中的任何人都在看这里...为什么最新的列在加载新页面时似乎变得更小,导致表扭曲并且每个<li>列<td>都包裹到下一行?
干杯
在我的项目中,我有一个名为的文件夹war.它最初是空的,并且受版本控制.该文件夹在其package阶段由Maven填充,Eclipse的WST插件从该文件夹部署Web应用程序.
我想要的是war在clean阶段中删除文件夹的内容,但不删除文件夹本身.我怎么做?到目前为止,我知道如何删除整个war文件夹:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<followSymLinks>false</followSymLinks>
<filesets>
<fileset>
<directory>${basedir}/war</directory>
</fileset>
</filesets>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何仅删除war文件夹的内容而不删除文件夹本身?我知道通过添加一些现有的排除项,该文件夹不会被删除.但是如何一般只删除文件夹的内容?
正如许多人已经注意到并遇到的那样,HashMap.put当同时使用时可以进入无限执行循环(参见GRIZZLY-1207,JGRP-525,可能是HHH-6414,以及这个SO 答案).
HashMap清楚地记录为不是线程安全的.显然,正确的解决方法是使用一个线程安全的实现Map,ConncurrentHashMap尤其如此.我对导致无限循环的并发时序更加好奇.我最近使用Java 7 JRE遇到了这个循环,并想了解确切的原因.例如,这是由同时多次看跌引起的吗?
在HashMap.put中查看显示HashMap.Entry包含指向下一个节点的链接(在存储桶中?).我假设这些链接正在腐蚀以包含循环引用,这导致无限循环.但是,我仍然不明白腐败是如何发生的.
我试图使用jmockit对我的项目进行单元测试并得到以下错误:
java.lang.UnsatisfiedLinkError: no attach in java.library.path
java.lang.IllegalStateException: Native library for Attach API not available in this JRE
at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:95)
at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:98)
at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:112)
at org.junit.runner.Runner.<clinit>(Runner.java:22)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.UnsatisfiedLinkError: no attach in java.library.path
Run Code Online (Sandbox Code Playgroud)
我分别在类路径中包含了jdk6/lib/tools.jar,jmockit.jar和junit.jar.任何线索为什么会发生这种情况?
好的,我有一个名为NamedSystems的类,它的唯一字段是一组NamedSystem.
我有一种方法可以通过某些标准找到NamedSystems.那不是很重要.当它得到结果时,一切正常.但是,当它找不到任何东西,从而返回null(或空 - 我已尝试过两种方式)设置时,我就会遇到问题.让我解释.
我正在使用Spring RestTemplate类,我在单元测试中进行这样的调用:
ResponseEntity<?> responseEntity = template.exchange(BASE_SERVICE_URL + "?
alias={aliasValue}&aliasAuthority={aliasAssigningAuthority}",
HttpMethod.GET, makeHttpEntity("xml"), NamedSystems.class,
alias1.getAlias(), alias1.getAuthority());
Run Code Online (Sandbox Code Playgroud)
现在,因为这通常会返回200,但我想返回204,我的服务中有一个拦截器,它确定ModelAndView是否是NamedSystem,如果它的集合为null.如果是,我然后将状态代码设置为NO_CONTENT(204).
当我运行junit测试时,我收到此错误:
org.springframework.web.client.RestClientException: Cannot extract response: no Content-Type found
Run Code Online (Sandbox Code Playgroud)
将状态设置为NO_CONTENT似乎擦除了内容类型字段(当我考虑它时这确实有意义).那为什么还要看呢?
Spring的HttpMessageConverterExtractor extractData方法:
public T extractData(ClientHttpResponse response) throws IOException {
MediaType contentType = response.getHeaders().getContentType();
if (contentType == null) {
throw new RestClientException("Cannot extract response: no Content-Type found");
}
for (HttpMessageConverter messageConverter : messageConverters) {
if (messageConverter.canRead(responseType, contentType)) {
if (logger.isDebugEnabled()) {
logger.debug("Reading [" + responseType.getName() + "] as \"" + contentType
+"\" using …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中使用注释.出于这个原因,我为注释创建了"hello world":
如下例子:
public class HelloAnnotation
{
@Foo(bar = "Hello World !")
public String str;
public static void main(final String[] args) throws Exception
{
System.out.println(HelloAnnotation.class.getField("str").getAnnotations().length);
}
}
Run Code Online (Sandbox Code Playgroud)
这是注释:
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
public @interface Foo
{
public String doTestTarget();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是main中的getAnnotations()是空的.我的代码出了什么问题?
我有一个问题,没有调用JSF CommandButton操作.我有一个托管bean roleController,如
@ManagedBean(name = "roleController")
@RequestScoped
public class RoleController {
public Role getSelectedRole() {
return selectedRole;
}
public void updateSelectedRole() {
System.out.println(selectedRole.getRole());
}
Run Code Online (Sandbox Code Playgroud)
在我的.jsf文件中,我正在尝试在h:commandButton上编辑调用updateSelectedRole操作,但它似乎不起作用.我试图将方法名称更改为不正确的名称,并且没有抛出异常 - 但是当我对其他表单执行相同操作时,抛出异常 - 因此很可能甚至不会调用该操作.
<h:panelGroup rendered="${param.action == 'edit'}">
<h:form>
<ol>
<li>
<label for="ID">
<h:outputText value="#{msg.roleEditID}" />
</label>
<h:inputText readonly="true"
value="#{roleController.selectedRole.id}" />
</li>
<li>
<label for="Role">
<h:outputText value="#{msg.roleEditRole}" />
</label>
<h:inputText value="#{roleController.selectedRole.role}" />
</li>
<li>
<h:commandButton value="#{msg.buttonUpdate}"
action="#{roleController.updateSelectedRole()}"/>
</li>
</ol>
</h:form>
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
我发现它可能是嵌套表单引起的,但在本例中并非如此.这个问题的根源是否可能是我的导航规则?
<navigation-rule>
<from-view-id>/admin/roles.xhtml</from-view-id>
<navigation-case>
<to-view-id>/admin/roles.xhtml</to-view-id>
<from-outcome>true</from-outcome>
<redirect>
<view-param>
<name>action</name>
<value>edit</value>
</view-param>
</redirect>
</navigation-case>
</navigation-rule>
Run Code Online (Sandbox Code Playgroud) 是否可以指定一个默认为null的注释?
我想要实现的是类似可选的注释属性.
例如
public @interface Foo {
Config value();
}
public @interface Config {
boolean ignoreUnknown() default false;
int steps() default 2;
}
Run Code Online (Sandbox Code Playgroud)
我想使用@Foo(没有指定值,所以它应该是某种可选的),我也希望能够写出这样的东西:
@Foo (
@Config(
ignoreUnknown = true,
steps = 10
)
)
Run Code Online (Sandbox Code Playgroud)
是否可以使用注释做这样的事情?
我不想做像这样的公共@interface Foo {
public @interface Foo {
boolean ignoreUnknown() default false;
int steps() default 2;
}
Run Code Online (Sandbox Code Playgroud)
因为我希望能够区分是否已设置属性(而不是它是否具有默认值).
描述它有点复杂,但我正在研究一个生成Java代码的Annotation Processor.但是在运行时我想设置一个应该用于所有@Foo的默认配置,除了那些使用@Config设置自己配置的人.
所以我想要的是这样的:
public @interface Foo {
Config value() default null;
}
Run Code Online (Sandbox Code Playgroud)
但据我所知,这是不可能的,对吧?有没有人知道这种可选属性的解决方法?
我想用 CloudFormation 创建 Route53 HostedZone,所以我想检查一下 Route53 中关于 HostedZone 的一些信息是否存在。
在我的情况下,我需要检查资源是否存在,忽略资源创建。我该如何处理这个问题。
我的 CloudFormation 模板如下所示。
"myDNSRecord" : {
"Type" : "AWS::Route53::RecordSet",
"Properties" : {
"HostedZoneName" : { "Ref" : "HostedZoneResource" },
"Comment" : "DNS name for my instance.",
"Name" : {
"Fn::Join" : [ "", [
{"Ref" : "Ec2Instance"}, ".",
{"Ref" : "AWS::Region"}, ".",
{"Ref" : "HostedZone"} ,"."
] ]
},
"Type" : "A",
"TTL" : "900",
"ResourceRecords" : [
{ "Fn::GetAtt" : [ "Ec2Instance", "PublicIp" ] }
]
}
}
Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-cloudformation devops infrastructure-as-code
我在服务器端有一个方法,它提供了有关我的数据库中注册的特定名称的信息.我正从我的Android应用程序访问它.
对服务器的请求正常完成.我要做的是根据我想要的名称将参数传递给服务器.
这是我的服务器端方法:
@RequestMapping("/android/played")
public ModelAndView getName(String name) {
System.out.println("Requested name: " + name);
........
}
Run Code Online (Sandbox Code Playgroud)
这是Android的请求:
private Name getName() {
RestTemplate restTemplate = new RestTemplate();
// Add the String message converter
restTemplate.getMessageConverters().add(
new MappingJacksonHttpMessageConverter());
restTemplate.setRequestFactory(
new HttpComponentsClientHttpRequestFactory());
String url = BASE_URL + "/android/played.json";
String nome = "Testing";
Map<String, String> params = new HashMap<String, String>();
params.put("name", nome);
return restTemplate.getForObject(url, Name.class, params);
}
Run Code Online (Sandbox Code Playgroud)
在服务器端,我只得到:
Requested name: null
Run Code Online (Sandbox Code Playgroud)
是否可以像这样向我的服务器发送参数?
java ×5
annotations ×2
rest ×2
spring-mvc ×2
ajax ×1
android ×1
concurrency ×1
devops ×1
get ×1
hashmap ×1
java-ee ×1
jmockit ×1
jquery ×1
jsf ×1
maven ×1
maven-2 ×1
resttemplate ×1
unit-testing ×1
web-services ×1