我使用Java 8的新DateTime API.
如何将LocalDate转换为Instant?我得到一个例外
LocalDate date = LocalDate.of(2012, 2, 2);
Instant instant = Instant.from(date);
Run Code Online (Sandbox Code Playgroud)
而且我不明白为什么.
如何重定向到同一页面(我不知道页面;重定向是在几个页面共享的菜单中完成的)?
我试过了
return "?faces-redirect=true";
Run Code Online (Sandbox Code Playgroud)
在操作方法的最后,但我收到一条错误消息,因为无法找到"?faces-redirect = true"的导航案例.
在此先感谢您的帮助.
我尝试过xmlns:h="jakarta.faces.html"、xmlns:h="http://jakarta.faces.html"、xmlns:h="https://jakarta.faces.html"和其他类似的字符串,但似乎没有任何效果。
我认为em.find找到的实体是由em自动管理的,甚至是一个事务,但下面的这个类似乎表明相反.我错了还是班上的错误是什么?
@Stateful
@TransactionAttribute(NOT_SUPPORTED)
public class CustomerGateway {
@PersistenceContext(unitName = "customersPU", type = EXTENDED)
private EntityManager em;
private Customer customer;
public Customer find(Long id) {
// customer is not managed!
this.customer = em.find(Customer.class, id);
// Print false!
System.out.println("Method find: " + em.contains(customer));
// Print false too (2 is the id of an entity)!
System.out.println("Method find: " + em.contains(em.find(Customer.class, 2L));
// A workaround
customer = em.merge(customer);
// Print true.
System.out.println("Method find after merge: " + em.contains(customer));
return this.customer;
}
Run Code Online (Sandbox Code Playgroud)
编辑1:实体的代码
@Entity
@NamedQuery(name …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用基于表单的身份验证的HttpServletRequest.login.
一切都好(容器告诉登录/密码是否良好),除了在用户输入登录后,我不知道如何将用户重定向到他要求的受保护页面(重新显示登录表单).怎么做?
在此先感谢您的帮助.
代码:
web.xml中:
<login-config>
<auth-method>FORM</auth-method>
<realm-name>security</realm-name>
<form-login-config>
<form-login-page>/faces/loginwithlogin.xhtml</form-login-page>
<form-error-page>/faces/noaut.xhtml</form-error-page>
</form-login-config>
</login-config>
Run Code Online (Sandbox Code Playgroud)
页面loginwithlogin.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Authentication</title>
</h:head>
<h:body>
<h:form>
Login :
<h:inputText value="#{login.login}" required="true" />
<p/>
Mot de passe :
<h:inputSecret value="#{login.password}" required="true" />
<p/>
<h:commandButton value="Connexion" action="#{login.submit}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:messages />
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
更新:没有Ajax它不起作用.
支持豆:
@Named
@SessionScoped
public class Login implements Serializable {
private String login;
private String password;
// getters and setters
...
public void submit() {
FacesContext context = …Run Code Online (Sandbox Code Playgroud) 我刚刚将 NetBeans 8.0.1 和 GlassFish 4.1 用于 2 个与 NetBeans 8.0 和 GlassFish 4.0 配合良好的旧项目。
现在(使用 NetBeans 8.0.1)我在项目部署期间收到错误“tInvalid resource : jdbc/nameOfTheSource__pm”。
JDBC 资源和连接池由 glassfish-resources.xml 定义(当我使用“创建持久单元”和“新数据源”选项定义新实体时由 NetBeans 生成)。
如果我通过 asadmin 的命令 add-resource 直接使用 glassfish-resources,则在服务器上,一切正常:创建了连接池和 JDBC 资源。所以问题不是来自这个文件。
就好像在部署过程中忽略了 glassfish-resources.xml。
有人有同样的问题(并有解释)吗?
我的环境:NetBeans 8.0.1、GlassFish 4.1、Java DB 10.10.1.2 - (1495037)(来自 Java 8.0)。
相关问题:在部署过程中如何使用 glassfish-resources?它不包含在 EAR 或 WAR 文件中。
在此先感谢您的帮助。