Java EE 7 WebSocket example

1. Createa a Java EE Web application called MyWebSocket for example. 2. In index.html:

2. Create a class Called WebSocketEndpoint. Here the most important annotations are @ServerEndpoint, @OnOpen, @OnClose and @OnError, in these methods you put whatever you want to get executed when these

3. The bean which will produce our fake data….

JSF simple ajax example

Here is a simple AJAX example in JSF (run on Glassfish). Just to note: for sending the value to the bean you use the execute attribute of f:ajax, and for displaying the output from the beans’s getter, you use the render attribute. 1. pom.xml

2. The xhtml page:

Hello from Facelets

3….

[java] check password against DB

To check the password against the database encoded value is simple, but it is not supported out of the box. You’ll have to convert the generated hash into hex format [code language=”java”] byte[] encoded = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < encoded.length; i++) { sb.append(Integer.toString((encoded[i] & 0xff) +…

web.xml examples for all versions of Servlet

1. Servlet 3.1

2. Servlet 3.0

3. Servlet 2.5

4. Servlet 2.4

5. Servlet 2.3

[Starter] EJB Session Bean based Web Server and Servlet client

EJB Session Bean based Web Server and Servlet client in Netbeans 1. Create a Class Library project which will hold your Remote EJB interfaces 2. Create new interface called WsHello

3. Create a new Project of type EJB Module 4. Create a new class in the EJB Module this class will implement your interface…

JSF – Add OmniFaces to your project

1. In pom.xml [code] <dependency> <groupId>org.omnifaces</groupId> <artifactId>omnifaces</artifactId> <version>2.0</version> </dependency> [/code] 2. You should put your xhtml pages under: [code]src/main/webapp/WEB-INF/faces-views[/code] 3. In your bean for example. Here strange is a xhtml file under the folder stated in point 2: [code] ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); ec.redirect(ec.getRequestContextPath() + "strange"); [/code]