将应用程序部署为EAR(使用1个EJB和1个WAR模块)与单独的模块有什么区别?我想使用GlassFish 3 Web配置文件,但它不支持EAR存档.我可以简单地将EJB和WAR用作单独的模块吗?还有其他选择吗?
我有URLRewirteFilter,它检查请求的域是否以www开头.并重定向到no-www url.当要重定向请求时,如何停止进一步处理(调用JSF应用程序,调用servlet等)?到目前为止我有这个:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String sn = req.getServerName().toLowerCase();
if (sn.startsWith("www.")) {
String url = "http://" + getDefaultDomain() + req.getContextPath() + req.getRequestURI();
HttpServletResponse resp = (HttpServletResponse) response;
resp.reset();
resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
resp.setHeader("Location", url);
}
chain.doFilter(request, response);
}
Run Code Online (Sandbox Code Playgroud) 我有TreeMap<String,String>
我需要转换为类似URI的字符串,然后返回到Map.我需要设置自定义分隔符.
是否可以为我做任何工具(番石榴,Apache公共?)?我知道,我可以编写简单的循环,但我正在寻找单行程:)
例如
key value
key1 val1
key2 val2
key1_val1|key2_val2
Run Code Online (Sandbox Code Playgroud) 我有很多带静态最终字段的类,用作默认值或配置.创建全局配置文件的最佳方法是什么?我应该将这些字段移动到单个静态类,使用属性文件还是什么?
编辑:我需要在java类和xhtml页面中使用这个值.价值观不依赖于环境.我可以编译项目来设置新值 - 没问题.
我正在使用动态创建的链接:
<h:link outcome="/page" value="#{name}">
<f:param name="name" value="#{name}"/>
</h:link>
Run Code Online (Sandbox Code Playgroud)
我想为f:param添加自定义转换器以从#{name}等中删除空格.但是f:param中没有转换器属性.
我有简单的jsf页面与视图参数和加载方法,正在处理这些参数:
<f:metadata>
<f:viewParam name="param1" value="#{bean.param1}"/>
<f:viewParam name="param2" value="#{bean.param2}"/>
<f:viewParam name="param3" value="#{bean.param3}"/>
<f:event type="preRenderView" listener="#{bean.load()}"/>
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
我还设置了一些初始值@PostConstruct
.如何将用户重定向到包含这些参数(非空)的新位置.例如用户在浏览器中输入:
domain.com/page.jsf
Run Code Online (Sandbox Code Playgroud)
并被重定向到:
domain.com/page.jsf?param1=valueA
Run Code Online (Sandbox Code Playgroud)
因为param1已设置@PostConstruct
.
另一个问题 - 我在页面上有链接引用相同的视图:
<h:link value="clickme">
<f:param name="param3" value="otherValue"/>
</h:link>
Run Code Online (Sandbox Code Playgroud)
当用户进入页面?param1=someValue
并点击链接时,被重定向到?param3=otherValue
但我想重定向到?param1=someValue¶m3=otherValue
.我知道我可以添加更多的参数,<h:link>
但是在每个参数中添加每个可能的参数都是困难的<h:link>
PS.我从这个主题JSF 2和Post/Redirect/Get使用BalusC提示?
我在生产环境中使用Glassfish 3.1.1 Web配置文件,它吃掉了太多的CPU.这是服务器设置:Windows Server 2008 R2 64位,Intel Xeon 8core @ 3,2GHz,8GB内存.我使用的是JDK 1.7u2 64bit.Glassfish JVM设置:
<jvm-options>-XX:+UseCompressedOops</jvm-options>
<jvm-options>-Xmn1g</jvm-options>
<jvm-options>-Xss128k</jvm-options>
<jvm-options>-XX:+UseParallelOldGC</jvm-options>
<jvm-options>-XX:ParallelGCThreads=4</jvm-options>
<jvm-options>-Xmx3g</jvm-options>
<jvm-options>-XX:+DisableExplicitGC</jvm-options>
<jvm-options>-d64</jvm-options>
<jvm-options>-XX:PermSize=256m</jvm-options>
<jvm-options>-Xms3g</jvm-options>
<jvm-options>-XX:MaxPermSize=256m</jvm-options>
<jvm-options>-XX:+AggressiveHeap</jvm-options>
Run Code Online (Sandbox Code Playgroud)
我还根据http://jfarcand.wordpress.com/2009/11/27/putting-glassfish-v3-in-production-essential-surviving-guide/调整了一些选项. 使用Glassfish几小时或一天CPU占15%到40%,有些占90%,应用程序没有响应.
[#|2012-02-03T10:30:46.837+0100|WARNING|glassfish3.1.1|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=43;_ThreadName=Thread-2;|GRIZZLY0023: Interrupting idle Thread: http-thread-pool-80(32).|#]
[#|2012-02-03T10:30:55.074+0100|WARNING|glassfish3.1.1|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=41;_ThreadName=Thread-2;|GRIZZLY0023: Interrupting idle Thread: http-thread-pool-80(41).|#]
[#|2012-02-03T10:30:56.665+0100|SEVERE|glassfish3.1.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=138;_ThreadName=Thread-2;|java.nio.channels.ClosedChannelException
at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:249)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:440)
at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:108)
at com.sun.grizzly.util.OutputWriter.flushChannel(OutputWriter.java:76)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flushChannel(SocketChannelOutputBuffer.java:326)
at com.sun.grizzly.http.SocketChannelOutputBuffer.flushBuffer(SocketChannelOutputBuffer.java:398)
at com.sun.grizzly.http.SocketChannelOutputBuffer.realWriteBytes(SocketChannelOutputBuffer.java:282)
at com.sun.grizzly.tcp.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:898)
at com.sun.grizzly.tcp.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:167)
at com.sun.grizzly.tcp.http11.filters.GzipOutputFilter$FakeOutputStream.write(GzipOutputFilter.java:223)
at java.util.zip.GZIPOutputStream.finish(GZIPOutputStream.java:169)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:238)
at com.sun.grizzly.tcp.http11.filters.GzipOutputFilter.recycle(GzipOutputFilter.java:186)
at com.sun.grizzly.http.SocketChannelOutputBuffer.recycle(SocketChannelOutputBuffer.java:417)
at com.sun.grizzly.http.ProcessorTask.finishResponse(ProcessorTask.java:817)
at com.sun.grizzly.http.ProcessorTask.postResponse(ProcessorTask.java:750)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:726)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at …
Run Code Online (Sandbox Code Playgroud) 是否可以使用mod_rewrite在内部重定向(因此url不会在地址栏中更改)到同一主机上的不同端口?例如
http://host.com:8080 -> http://host.com:9999/myapplication/?param=val
Run Code Online (Sandbox Code Playgroud) 我在Glassfish 3上运行JavaEE 6 Web应用程序.我使用JAAS和jdbcRealm以及默认主体到角色映射.在我的数据库中,我有用于将用户名映射到其角色的表:
username | role
----------+-------
john | admin
mary | user
Run Code Online (Sandbox Code Playgroud)
为什么我需要再次在我的列表中列出这些角色web.xml
?
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)
没有它isUserInRole()
总是返回false
.
假设我们得到了一个接受一个参数的简单页面:
<f:viewParam name="name" value="#{bean.name}"/>
Run Code Online (Sandbox Code Playgroud)
当用户进入时http://localhost/myapp/?name=Joe
,则#{bean.name}
设置为Joe
.然后,如果用户去http://localhost/myapp/
或http://localhost/myapp/?something=Else
,然后#{bean.name}
仍然设置Joe
,但我希望它null
.怎么做到这一点?
java ×5
java-ee ×3
jsf ×2
jsf-2 ×2
viewparams ×2
apache ×1
cpu-usage ×1
ear ×1
el ×1
glassfish-3 ×1
guava ×1
jaas ×1
java-ee-6 ×1
map ×1
mod-rewrite ×1
performance ×1
war ×1