29 September 2024
Server-side HTML generation
I have been trying out htmx with Kotlin and http4k.
To use htmx, you need some way of generating HTML on the server. In Kotlin, you have plenty of options, both Kotlin specific ones and everything from the broader Java/JVM ecosystem. There are two main categories here, template languages and internal DSLs.
Given Kotlin’s good support for internal DSLs, I decided to explore that route, and try kotlinx.html and HtmlFlow. They both make great promises of encoding the entire HTML standard and enforce valid HTML at compile time.
13 October 2013
Using an embedded SQL database in Java web application
You have a Java web application needing a relational SQL database. According to JavaEE conventions, you declare the DataSource in web.xml:
<resource-ref> <res-ref-name>jdbc/DS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> and then fetch it in code with (DataSource)new InitialContext().lookup("java:comp/env/jdbc/DS").
Using Maven, Jetty and HSQLDB, you can very easily run the web application for local testing without having to setup neither a web container, nor a database. Add this to pom.xml:
<build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.
24 August 2012
How to design a RESTful protocol
What is REST? In most cases, it is sufficient say that REST is a way to design a network protocol based on HTTP. I perfer to call it a RESTful protocol, but it can also be called RESTful API or RESTful Web Service. It is important to keep in mind that it technically is a network protocol, and not an API like an interface with some methods in a regular programming language.
20 July 2011
PHP session timeout
The developers of PHP has, in their infinite wisdom, decided that the default session timeout should be 24 minutes (1440 seconds).
This means that if you have a MediaWiki wiki and are editing a single page for half an hour and then click the save button, you are logged out and all your changes are lost. I just learned this the hard way.
Fortunately, you can change this with the session.
25 November 2010
Web application frameworks in Java
When you know which type of web application you are to develop, it’s time to have a look at some possible choices.
I have tried to categorize some modern and popular web application frameworks in Java.
Simple server driven MVC page based This category contains the traditional frameworks used for developing web applications with purely server driven application logic. They are based on complete HTML pages and uses the Model-View-Controller design pattern.
25 November 2010
Web applications and web frameworks
If you are to develop a web application, there are a lot if frameworks to choose between.
I assume that the web application by its nature needs to have bi-directional communication between the web browser and the server during the execution, initial downloading of resources is not enough. I also assume that the available technologies are HTML, CSS and JavaScript/AJAX; no Flash, Java applets, ActiveX, Silverlight or other browser plug-ins are used.
9 June 2010
Using Vaadin with Maven
Vaadin is a comprehensive framework for developing web applications in Java. The Vaadin web site presents a number of ways to use Vaadin with Maven, but I am not completely satisfied with any of those. Here is how I do it.
Use a pom.xml like this:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.thecompany</groupId> <artifactId>theapp</artifactId> <version>1.0</version> <packaging>war</packaging> <name>The App</name> <dependencies> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin</artifactId> <version>6.3.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.
16 April 2010
How to implement RESTful JSON Web Services in Java
You can implement RESTful Web Services in Java using the JAX-RS framework.
JAX-RS is part of the JavaEE 6 platform. But if you are not using a JavaEE 6 application server, you can use the reference implementation Jersey and embed it in any web application server.
However, it’s quite awkward to produce JSON output from Jersey.
Jersey has some support for producing JSON via JAXB, but to get the NATURAL encoding (which you probably want) you need JAXB 2.
17 July 2009
Misuse of HTTP GET is a cardinal sin
According to the RESTful style, you should make use of the four HTTP methods GET, POST, PUT and DELETE. However, in many cases only GET and POST is used, and POST is used when you really should use PUT or DELETE. I consider this as a quite minor issue.
However, using GET instead of POST (or PUT or DELETE) is much worse.
The current HTTP 1.1 specfication (RFC-2616) clearly states that a GET request must be safe, i.
23 April 2009
Type safe JSP and JSTL
When using JavaServer Pages, you want to use JSTL to be able to to flow-control (iterations and conditionals) in a reasonable way. And the recommended way to use JSTL is to use the Expression Language (EL).
However, using EL is not a good idea at all. Contrary to Java and plain JSP, EL lacks static typing. This means that many errors which the compiler can catch is not detected until runtime when using EL.
8 September 2006
Poor Javascript performance is an obstacle in AJAX development
I’m currently developing my first AJAX based web application. The goal is to have a pure AJAX application, i.e. never reload the entire page, use only background XMLHTTPRequest to contact the server.
My observations so far is that it is possible to do most of the application logic I need. But the performance of Javascript execution in the browser is a big obstacle. The application is centered around a list of data items in a scrollable area.