java-ee

Any chance of formatting Date object returned by resultset getDate() method

徘徊边缘 提交于 2019-12-13 21:07:21
问题 I want to skip the parsing of date and formatting it. Instead i directly want to fetch the date from database in custom format. Is this possible ? 回答1: Yes, change your SQL query to format the date. For example, if you use oracle, you need to use the function TO_CHAR(dateColumn, 'YYYY/MM/DD'), and that will return a String column with the date formatted as '2012/09/14'. 回答2: You can set format in your query. (My example is run on sqlserver) something like.. SELECT CONVERT (VARCHAR, GETDATE(),

How to get and use a session object to populate a datatable in JSF?

让人想犯罪 __ 提交于 2019-12-13 20:53:08
问题 I am trying to populate a datatable in my jsf page. Here is what i do: I first add the user to the session who logins to the system in my LoginBean: @ManagedBean(name = "loginBean") @Dependent @SessionScoped public void loginCheck() { Customer currentCustomer = new Customer(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7),accounts); FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("currentCustomer",

JavaEE Websocket: closing browser tab closes all sessions irrespective of browser

怎甘沉沦 提交于 2019-12-13 20:45:45
问题 I have a websocket endpoint as @ServerEndpoint("/tweets") public class TweetStreamServer { private static final Logger LOGGER = LoggerFactory.getLogger(TweetStreamServer.class); @OnMessage public void tweets(final String message, final Session session) throws IOException, InterruptedException { System.out.println("session id:" + session.getId() + ", search term: " + message); final Client twitterClient = TwitterHoseBird.getInstance(message); while (!session.getOpenSessions().isEmpty()) { for

Maven, run a java method or script before war is about to be built

╄→гoц情女王★ 提交于 2019-12-13 20:43:00
问题 I am thinking of using a template engine to generate the web.xml and other things. Is there as way to to run a java file or a script before the maven install command ? Or before the war is generated. I am not sure what the phase should be, but basically before anyone else looks at the web.xml so I can touch it to make a new valid one . 回答1: You can use the exec-maven-plugin to run either a program/script (using the exec goal) or a Java program (using the java goal). The phase immediately

Generating Own Session Id in JSF

回眸只為那壹抹淺笑 提交于 2019-12-13 20:32:39
问题 I have a web application in which we use JSF framework. I have been diving deep into the security part for web application and hence I was looking to generate my own unique session ID(using encryption algorithm and assign it to every new session which gets created once user logs in. Can anyone please guide me on how to set manual generated session id in session and ensure with each request that session id is transmitted. Thanks. 回答1: I really doubt you'll generate session IDs that are more

Exception in using appclient jar in EJB 3 :javax.ejb.EJBException: java.rmi.MarshalException:

混江龙づ霸主 提交于 2019-12-13 19:43:14
问题 I am trying to learn ejb 3 and facing an issue in the below mentioned scenario which I am not able to figure out. I am having one Entity (Book) to store book related data. I have created Stateless Bean and Remote interfaces and deployed the jar in glassfish 4. The basic application connects to a main method where I need to get the details of the book using appclient. Here I am getting an error "javax.ejb.EJBException: java.rmi.MarshalException:" Please look into the below snippets for more

Link doesn't work when I access it via localhost

老子叫甜甜 提交于 2019-12-13 19:26:16
问题 The following servlet creates a directory named Shared and then copies the video into this directory.Next it presents the link,to download this video. But when I click the link,nothing happens. Why is this ? @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter writer = response.getWriter(); String path = request.getServletContext().getRealPath("/") + "Shared/" + "sweet

How to show Hibernate query result in Primefaces datatable?

别等时光非礼了梦想. 提交于 2019-12-13 19:10:01
问题 It can be an easy problem, I have a native query with hibernate in my managedbean, my goal is to show it in a datatable of primefaces implementation. public List<User> retrieveAllUserName() { Transaction tx = null; Session session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); //Native Query Query q = session.createSQLQuery("select name from user"); List<User> ls = q.list(); System.out.println("query executed"); for (int i = 0; i < ls.size(); i++) { System

Log4j2.xml configuration file location for EAR

拜拜、爱过 提交于 2019-12-13 19:05:23
问题 I have a Java EE application packaged with ejbs and war. Following is the structure of the EAR: myapp.ear -lib -META-INF -ejbjar1.jar -ejbjar2.jar -mywebapp.war I need to use log4j2 so I have tried to configure it at first from the web.xml by following instructions to initialize Log4j 2 in a web application but when I am creating the Logger in an EJB it is throwing: ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. The

JavaEE - EJB over SSL works only if client and server are at the same host

你。 提交于 2019-12-13 19:02:14
问题 Please help me. I can do nothing with it. I have gf 4.0.1 and swing client. I want to get EJB over SSL. I've set all certificates. However, I can get it work only when client and server are at the same host. What I see in tcpdump when they are at the same host: ........ 10.0.17.2.48524 > 10.0.17.2.3820: Flags [P.], cksum 0x378f (incorrect -> 0xf2b6), seq 399:756, ack 1085, win 273, options [nop,nop,TS val 347297976 ecr 347297966], length 357 13:01:26.334898 IP (tos 0x0, ttl 64, id 51559,