默认情况下,MVC包在客户端上缓存1年.是否可以手动设置它的客户端头(针对1个特定的捆绑包)?
我需要的是为我的一个捆绑包设置自定义过期标头.我不能依赖"v = hash"查询字符串,因为这个包是用于外部网站的,每次我更改时它们都不会更改指向我的包的网址.
我试过的是创建一个自定义的Bundle类(继承Bundle)并覆盖GenerateBundleResponse()方法.这样我可以控制服务器缓存,但自定义客户端缓存的唯一方法是设置BundleResponse.Cacheability(public,private,nocache等).但我无法手动设置标头.我可以访问BundleContext(它是HttpContext),但是当我在该上下文中设置标题时,它也会对所有其他请求产生影响.
我正在尝试在Oracle的文档中给出的示例.java文件在此处显示在该页面中.现在使用这个java文件,我将LabelsBundle.properties
文件保存在同一目录中.
# This is the default LabelsBundle.properties file
s1 = computer
s2 = disk
s3 = monitor
s4 = keyboard
Run Code Online (Sandbox Code Playgroud)
似乎在读取值时不会忽略尾随空格,并忽略前导空格.
所以,如果我想要领先的空间,我该怎么办?
换句话说,我需要做什么才能读取s1
as 的值
computer
Run Code Online (Sandbox Code Playgroud)
代替
computer
Run Code Online (Sandbox Code Playgroud)
?
label.my.answer=My Answer
Run Code Online (Sandbox Code Playgroud)
我想在上面的键的末尾故意添加空格(例如,我想在结尾处有2个空格"My Answer "
)
目前java.util.ResourceBundle功能在检索值时修剪了这段代码
我正在使用ResourceBundle和Locale来查找属性值.很简单,代码如下所示:
public static String getPropertyValue(Locale locale, String resourceName, String key) {
ResourceBundle resource = ResourceBundle.getBundle(resourceName, locale);
return resource.getString(key);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是关于表现.缓存方法比访问类路径上的属性文件更快还是更好?我的理解是,ResourceBundle的性能总的来说非常好.
属性文件(在这种情况下)少于30行(即,~30个键/值对).
我质疑性能,因为我们可以在高负载页面上使用类似的方法,并且按需查找方法可能证明是昂贵的.
我有一个资源包,其中包含以下条目:
entry1=value1
entry2=value2
entry3=value3
Run Code Online (Sandbox Code Playgroud)
在我的JSF页面中,我试图动态地使用这些键.条目的ID来自托管bean.我认为它应该是这样的:
<h:outputText value="#{msg['entry' managedBean.entryIndex]}"/>
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
jsf resourcebundle el string-concatenation internationalization
我在主jar中打包了一些资源包
widget_en.properties
widget_de.properties
Run Code Online (Sandbox Code Playgroud)
我根据我的默认语言环境检索资源包作为folows
ResourceBundle.getBundle("widget", Locale.getDefault());
Run Code Online (Sandbox Code Playgroud)
但我想向用户提供支持的可用语言列表,以便选择可能与其计算机默认的语言不同的语言
但我在ResourceBundle中找不到列出可用语言环境的方法,我不想硬编码列表,因为我可能忘记在添加另一个资源包时更新它.
编辑
因为我只为不同的语言资源包(我没有国家改进)所以我通过迭代所有已知的语言代码并检查每一个作为资源来生成列表.
String[]langs = Locale.getISOLanguages();
for(String lang:langs)
{
URL rb = ClassLoader.getSystemResource("widget_"+lang+".properties");
if(rb!=null)
{
System.out.println("Found:"+rb.toString());
}
}
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个静态库和一个资源包,用于在多个项目中重用代码和资产.
在静态库中,我有一个管理器类,其唯一目的是创建其他的UIViewControllers
,其视图是从.xib
文件创建的(使用常用initWithNibName:bundle:
方法).
在Interface Builder中创建视图时,图像显示正确.但是,当我在模拟器上运行应用程序时,我收到此错误:
Could not load the "<image_name.png>" image referenced from a nib in the
bundle with identifier "com.<my_company>.<app_identifer>"
Run Code Online (Sandbox Code Playgroud)
经过几个小时的研磨,我终于检查了资源包,发现.png文件不在其中!相反,相反名称的.tiff文件(不包括@ 2x版本).
所有图像都包含在捆绑包的构建阶段,在复制包资源下,我已经在其他iOS项目中使用了这些图像(因此它们没有被破坏).
还有其他人经历过这个吗?是否可以安全地假设图像将始终作为.tiff添加到包中?(如果是这样,将界面生成器中的图像名称更改为.tiff是否安全?)或者我在这里做错了什么?
感谢您的帮助.
我发现的任何东西都无法帮助我解决这个具体案例.我最近从一个普通的旧的Java Web应用程序项目(正在运行)切换到一个maven web项目.我得到以下运行时异常:
java.util.MissingResourceException: Can't find bundle for base name com.myapp.config, locale en
Run Code Online (Sandbox Code Playgroud)
我正在使用Netbeans创建一个JSF 2.0,Spring和Hibernate Web应用程序.我有以下目录结构:
src\main\java\com\myapp包含config.properties
src\main\resources空
目标\ myapp\WEB-INF\classes\com\myapp包含没有config.properties的编译类文件
src\main\java\com\myapp包含config.properties
检查目标文件夹中的WAR文件不会显示属性文件的任何迹象,因此就好像Maven构建插件没有复制属性文件一样.我知道你可以在pom中放置一个标签,但它对我不起作用.下面的链接提到资源文件夹(对我来说是空的)在构建期间包含其内容但是如果是这种情况,你如何从Netbeans做到这一点?我只希望将属性文件与我的war一起打包,以便在将其部署到服务器时可以访问它.
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
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.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>myapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>java.net</id>
<name>Repository hosting the Java EE 6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.1.8</version>
</dependency>
<dependency>
<groupId>net.authorize</groupId>
<artifactId>java-anet-sdk</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> …
Run Code Online (Sandbox Code Playgroud) 是否有可能做到这一点 ?目前这样做是这样的:
<bean id="resource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>content.Language</value>
</list>
</property>
</bean>
@Autowired
protected MessageSource resource;
protected String getMessage(String code, Object[] object, Locale locale) {
return resource.getMessage(code, object, locale);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法通过@Value注释获取属性?
<util:properties id="generals" location="classpath:portlet.properties" />
@Value("#{generals['supported.lang.codes']}")
public String langCodes;
Run Code Online (Sandbox Code Playgroud)
因为必须调用该方法通常很好,但是例如在单元测试时,这很痛苦......在某些情况下,webdriver的PageObject模式对象没有初始化,这将是非常有帮助的
我想在cocoapod库中包含图像资源,但我无法访问它们.我已经阅读了这些资源以寻求帮助:
但是,没有人指出我访问资源的方向.我尝试过以下方法:
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets"] URLForResource:@"my-image@2x" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets"] URLForResource:@"my-image" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle bundleWithIdentifier:@"Assets.bundle"] URLForResource:@"my-image" withExtension:@"png"]]]
[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle mainBundle] URLForResource:@"my-image" withExtension:@"png"]]]
[[UIImage imageWithData:[NSData dataWithContentsOfURL:[(NSBundle *)[NSBundle mainBundle] URLForResource:@"my-image@2x" withExtension:@"png"]]]
[UIImage imageNamed:@"my-asset"]
[UIImage imageNamed:@"my-asset@2x.png"]
Run Code Online (Sandbox Code Playgroud)
但它们都不起作用.
我已经使用这些替代方案设置了podspec,并且不能使用上述方法:
s.resources = ['Pod/Assets/*.{png, jpg}', 'Pod/Assets/**/*.{png, jpg}']
s.resource_bundles = {
'Assets' => ['Pod/Assets/*.{png, jpg}', 'Pod/Assets/**/*.{png, jpg}']
}
Run Code Online (Sandbox Code Playgroud)
资源显示在"开发窗口/我的应用程序/资源"之后pod update
,但是在我的生命中我无法访问它们.没有任何捆绑,也没有任何名为"资产"的东西.
任何帮助或指导将不胜感激.
resourcebundle ×10
java ×5
ios ×2
annotations ×1
asp.net-mvc ×1
cocoapods ×1
el ×1
ipad ×1
iphone ×1
java-ee-6 ×1
jsf ×1
localization ×1
maven ×1
performance ×1
spring ×1
uiimage ×1
uiimageview ×1
whitespace ×1
xcode ×1