我有一段时间远离Java EE,但我对所有这些东西都有一个基本的想法.
我在这里阅读JTDS文档:
http://jtds.sourceforge.net/features.html
它说它提供了语句池和连接池,但没有提供连接池实现.
随意添加更多细节到您的答案
(无论您发现什么重要;我没有明确询问的事情),
因为我对此非常困惑.
我有以下代码.这就是我理解它的方式.
在第一种情况下,三元运算符返回的值y,因为x=4和打印语句打印5,符合市场预期.
在第二种情况下,三元运算符首先将y的值赋给x,然后返回该值.再次,它按预期打印5.
在第三种情况下,三元运算符x=y位于以下的左侧:和 x=z右侧:.我希望这与第二种情况非常相似.但是,这个语句甚至没有编译.
任何理解这一点的帮助将非常感激.
public class Test {
public static void main(String[] args) {
int x = 4;
int y = 5;
int z = -1;
x = (x == 4) ? y : z; // compiles and runs fine
System.out.println(x + " " + y + " " + z);
x = (x == 4) ? x = y : z; // compiles and runs fine …Run Code Online (Sandbox Code Playgroud) 我是EJB和hibernate的新手,以下让我感到困惑,因为每当我寻找明确的答案时似乎都会有矛盾.题:
以下列方式将实体管理器直接注入无状态bean是否可以线程安全?
@Stateless
public class SomeBean implements SomeInterface {
//..
@Inject
private EntityManager entityManager;
//... non related transaction1()
//... non related transaction2()
Run Code Online (Sandbox Code Playgroud)
EntityManager是否可以注入每个无状态bean都有自己的实例或共享实例?
根据Hibernate文档:
一个EntityManager是应该被使用一次,单个业务流程的廉价,非线程安全的对象,一个工作单位,然后丢弃.
EJB容器是否使其线程安全?
根据EJB文档,无状态会话bean本身就是线程安全的,因为不允许不同的客户端同时在同一个bean上运行.
然而,我看过的例子中,EntityManagerFactory应注射代替EntityManager,如果EntityManager直接注射应在状态bean来完成.
总是将EJB直接注入无状态bean(如上所示)或者什么是无用的情况下是否安全?
我的问题很简单.我正在使用PrimeFaces 4.0和布局组件.
当我尝试调整CSS时,问题就来了.我想把它的背景设置为无,我尝试了经典,style="background: none !important但它忽略了我,然后我检查谷歌浏览器中的元素,看到.ui-widget-content风格是我想要隐藏的那个然后我试试这个:
<p:layout style="min-width:400px;min-height:1000px; .ui-widget-content {background: none !important;}">
<p:layoutUnit position="west" size="620" minSize="40" style=".ui-widget-content {background: none !important;}">
Run Code Online (Sandbox Code Playgroud)
但它仍然无效.另外,在我的css主题中,我有:
body .ui-widget-content {
border-style: hidden;
border-color: white;
border-width: 0px;
color: #4f4f4f;
}
Run Code Online (Sandbox Code Playgroud)
如果我添加背景:无,它确实有效,但搞砸了我整个应用程序的主题.有没有办法隐藏单个小部件内容的背景?
我想使用JSF实现带附件的邮件.我试过这段代码:
private Part file;
private String sendFromGMail(String from, String pass, String[] to, String subject, String body)
{
String status;
Properties props = System.getProperties();
String host = "smtp.gmail.com";
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
MimeMessage message = new MimeMessage(session);
try
{
message.setFrom(new InternetAddress(from));
InternetAddress[] toAddress = new InternetAddress[to.length];
// To get the array of addresses
for (int i = 0; i < to.length; i++)
{
toAddress[i] = new InternetAddress(to[i]);
}
for …Run Code Online (Sandbox Code Playgroud) 更新提供的实体的EJB方法(使用CMT):
@Override
@SuppressWarnings("unchecked")
public boolean update(Entity entity) throws OptimisticLockException {
// Code to merge the entity.
return true;
}
Run Code Online (Sandbox Code Playgroud)
javax.persistence.OptimisticLockException如果检测到并发更新,则将抛出,这将由调用者(托管bean)精确处理.
public void onRowEdit(RowEditEvent event) {
try {
service.update((Entity) event.getObject())
} catch(OptimisticLockException e) {
// Add a user-friendly faces message.
}
}
Run Code Online (Sandbox Code Playgroud)
但这样做会使javax.persistence表达层上的API 产生额外的依赖性,这是一种导致紧密耦合的设计气味.
应该包装哪个例外,以便完全省略紧耦合问题?或者是否有一种标准方法来处理此异常,这反过来又不会导致在表示层上强制执行任何服务层依赖性?
顺便说一句,我发现在EJB中(在服务层本身上)捕获此异常然后向客户端(JSF)返回一个标志值是笨拙的.
我有一个在GlassFish 4.1/Java EE 7(NetBeans 8.0.2)上运行的完整Java EE项目,不使用Apache Maven.
根据项目功能,必须将CDI依赖项添加到项目/模块(即EE模块和Web模块(以及类库,如果有)).
很长一段时间以来,我一直在混淆人们建议将"Java EE 7 API库"或"Java EE Web 7 API库"添加到编译时类路径中作为CDI依赖项(这些库捆绑在NetBeans和使用NetBeans时可以随时使用.
由于这些库包含一组API,可能是从Servlet API开始的整个Java EE堆栈,因此当CDI功能为CDI时,将其中一个库添加到编译时类路径(特别是在EE项目中)是没有意义的. Java EE应用程序中需要的.
为什么在NetBeans项目中多次建议添加其中一个库,只是cdi-api.jar因为CDI依赖性足够?
在Java EE应用程序中需要CDI功能时,我没有在此站点上找到关于在NetBeans项目中准确添加哪个库的其他地方的规范答案.cdi-api.jar顺便说一句,添加只会很好.
给定WebSocket端点如下.
@ServerEndpoint(value = "/Push/CartPush/{token}")
public final class CartPush {
// ...
}
Run Code Online (Sandbox Code Playgroud)
端点能够接受路径参数{token}.但是,path参数是可选的,它是在Java Script中在运行时动态确定的.在JavaScript中跳过此参数,如下所示404.
var ws = new WebSocket("wss://localhost:8443/ContextPath/Push/CartPush");
Run Code Online (Sandbox Code Playgroud)
WebSocket连接
'wss://localhost:8443/ContextPath/Push/CartPush'失败:WebSocket握手期间出错:意外响应代码:404
它使得令牌值必须如下.
var token = "token value";
var ws = new WebSocket("wss://localhost:8443/ContextPath/Push/CartPush" + "/" + token);
Run Code Online (Sandbox Code Playgroud)
为了排除除GET和之外的所有不需要的HTTP方法POST,我使用以下限制或约束以及使用适当的URL模式和角色映射的Servlet安全性约束web.xml.
<security-constraint>
<web-resource-collection>
<web-resource-name>Disable unneeded HTTP methods by 403</web-resource-name>
<url-pattern>/Public/*</url-pattern>
<url-pattern>/Push/*</url-pattern>
<url-pattern>/javax.faces.resource/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
</security-constraint>
<deny-uncovered-http-methods/> <!-- Requires Servlet 3.1 -->
Run Code Online (Sandbox Code Playgroud)
如何使给定的路径参数可选?
正在使用的服务器是WildFly 10.0.0 final/Java EE 7.
我正在将现有的 spring 3、PrimeFaces 5 应用程序转换为 spring 启动应用程序。以下是我的主要依赖项,
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.3.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的 push servlet bean 的 spring 配置是,
@Bean
ServletRegistrationBean pushServletRegistration(){
ServletRegistrationBean pushServlet=new ServletRegistrationBean();
Map<String, String> mapParams=new HashMap<>();
mapParams.put("org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.UUIDBroadcasterCache");
pushServlet.setServlet(new PushServlet());
pushServlet.setInitParameters(mapParams);
pushServlet.addUrlMappings("/primepush/*");
pushServlet.setName("Push Servlet");
pushServlet.setAsyncSupported(true);
pushServlet.setLoadOnStartup(100);
return pushServlet;
}
Run Code Online (Sandbox Code Playgroud)
以下是我的推送终点
@PushEndpoint("/event")
public class EventMapNotifyResource {
@OnMessage(encoders = {JSONEncoder.class})
public Event onMessage(Event coordinate) {
return coordinate;
}
}
Run Code Online (Sandbox Code Playgroud)
我在应用程序启动时收到以下信息,
2016-03-22 14:49:48.539 INFO 70488 --- [ restartedMain] org.atmosphere.cpr.AtmosphereFramework : …Run Code Online (Sandbox Code Playgroud) 我的项目非常简单.它有两个名为的TextField latField和longField.我要做的就是使用该getText()方法打印这些字段中包含的字符串值,并偶尔使用该setText()方法设置它们.
请注意,我正在使用javafx场景构建器,并且有一个FXMLDocument和FXMLDocumentController
FXMLDocument.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" style="-fx-background-color: #eee;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pokemongocontroller.FXMLDocumentController">
<children>
<Label fx:id="label" layoutX="114.0" layoutY="92.0" minHeight="16" minWidth="69" />
<Button id="upButton" layoutX="140.0" layoutY="84.0" mnemonicParsing="false" onAction="#upButtonClick" prefHeight="36.0" prefWidth="38.0" text="U" />
<Button id="downButton" layoutX="140.0" layoutY="140.0" mnemonicParsing="false" onAction="#downButtonClick" prefHeight="36.0" prefWidth="38.0" text="D" />
<Button id="leftButton" layoutX="94.0" layoutY="106.0" mnemonicParsing="false" onAction="#leftButtonClick" prefHeight="36.0" prefWidth="38.0" text="L" />
<Button id="rightButton" layoutX="188.0" layoutY="106.0" mnemonicParsing="false" onAction="#rightButtonClick" …Run Code Online (Sandbox Code Playgroud) java-ee ×5
java ×4
jsf ×3
ejb ×2
primefaces ×2
atmosphere ×1
css ×1
endpoint ×1
fxml ×1
glassfish ×1
hibernate ×1
jakarta-mail ×1
java-ee-7 ×1
javafx ×1
jdbc ×1
jtds ×1
netbeans ×1
spring-boot ×1
syntax ×1
websocket ×1