java-ee

EJB @Schedule issue

五迷三道 提交于 2019-12-24 02:42:08
问题 I need to schedule a task in my web application. The task needs to use a member field of the Servlet that is initialized during deployment. I have used the EJB @Schedule . However when the task is fired, the member field is null. I guess that the cause lies in the fact that I had to add the @Stateless annotation to the servlet in order to make the @Schedule work, and my Servlet needs to preserve its state indeed? If yes, how can I fire my task in a simple and efficace way? Using GlassFish 3

EJB @Schedule issue

时光怂恿深爱的人放手 提交于 2019-12-24 02:42:05
问题 I need to schedule a task in my web application. The task needs to use a member field of the Servlet that is initialized during deployment. I have used the EJB @Schedule . However when the task is fired, the member field is null. I guess that the cause lies in the fact that I had to add the @Stateless annotation to the servlet in order to make the @Schedule work, and my Servlet needs to preserve its state indeed? If yes, how can I fire my task in a simple and efficace way? Using GlassFish 3

Confusion about Java SE and Java EE

自作多情 提交于 2019-12-24 02:38:16
问题 I am using Java SE with Eclipse happily but now I am going to write a "send mail" program which requires javax.mail package. I found that in Java EE so I downloaded one (180MB) and I know that Java EE installation needs SE JDK/JRE. Because I installed Java SE in c:\java\jdk1.7 (not the default path) I use -j c:\java\jdk1.7 to install Java EE. I have several questions about it. How could I let Eclipse to load the Java EE package? Should I change the JRE in Java EE? Now Eclipse still only know

Excel .xlsx file not opening after downloading the file from the server in java

给你一囗甜甜゛ 提交于 2019-12-24 02:23:44
问题 Here is my sample code. I am using eclipse , tomcat server .Browser as IE9. protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); ServletContext context = request.getServletContext(); @SuppressWarnings("unchecked") List<Student> students = (List<Student>) context.getAttribute("students"); PrintWriter out = response.getWriter(); for

Should I use @NamedQuery annotation or addNamedQuery method?

随声附和 提交于 2019-12-24 02:22:57
问题 Currently, the JPA entities that comprise my application have an @NamedQueries block that contains many @NamedQuery annotations. This works well but some of my entities have over 80 @NamedQuery annotations and are getting difficult to maintain. I now need to add sorting to my queries and do not want to create additional @NamedQuery annotations. During my research, I discover the JPA 2.1 EntityManagerFactory.addNamedQuery method. This seems to be the answer to my prayers. I could create an

ORA-01400: Cannot insert null into (TABLE.COLUMN) (Hibernate)

谁说我不能喝 提交于 2019-12-24 02:16:35
问题 I'm using hibernate 4.3, oracle 11: When I want to insert an employee, (it have a relationship one to many with category (one category have many employees)), first I Insert a category to db, then I try to insert an employee to the db and get an exception, the code of the entities was generated by hibernate, so I don't know what's wrong, The problem seems to be that Hibernate is not inserting ID_CAT when I'm inserting an employee, what im doing wrong? I also tried to generate tables from

How concerned should we be about thread safety with JSF managed beans?

浪尽此生 提交于 2019-12-24 02:14:29
问题 I'm working on a JSF 1.2 project which has AJAX functionality on it's pages (using RichFaces). My bean builds a list of objects to be edited and then has methods to support the editing and the bean is session-scoped. I will be using a a4j:queue so that only one AJAX call can happen at a time. I'm curious if it is wise to use synchronization (locks on objects, or perhaps collections from java.util.concurrent) in the managed bean. Is the extra work needed to implement synchronization/thread

How to close an entitymanager when used with Jackson and Jax-rs

五迷三道 提交于 2019-12-24 02:13:30
问题 I am using JPA (hibernate), JAX-RS (Jersey) and Jackson. How can I close my entity manager after my packet is built and sent? The following does not work and gives me an error. It appears to be calling em.close() before the response is completed. @GET @Produces(MediaType.APPLICATION_JSON) public Response getNode( @QueryParam("nodeId") long nodeId ){ try { Node node = em.find(Node.class, nodeId); if (node == null) throw new WebApplicationException(Response.Status.NOT_FOUND); Response response

I need a thread in Web/JavaEE container to complete AsyncContext objs in same JVM

邮差的信 提交于 2019-12-24 02:13:20
问题 I need a thread in Web/JavaEE container to fetch information from an external source and complete corresponding AsyncContext objs in same JVM. I wish to have a zero-added-latency solution, so periodic polling or a timer is ruled out. I could start a thread but I believe it is frowned upon in a Web container and not portable. Q1. Is it possible to run a thread portably in a Java EE container instead? Q2. If I want to run a thread in a Web Container anyway, what is the "least of all evil" ways?

Pass XML document via attribute or body to JSP custom tag

房东的猫 提交于 2019-12-24 02:09:33
问题 I wonder if it's possible to pass an xml document to a pure jstl-defined JSP custom tag either as: the body of the custom tag, such as: <mt:mytag> <people> <person name="bob" age="23" /> <person name="sue" age="45" /> <person name="moe" age="35" /> </people> <mt:mytag> or as an attribute of the tag like this: <mt:mytag message="http://link.to.document.xml" /> This is the tag itself <%@tag description="xml parser" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix