From Wikipedia, the free encyclopedia
Jump to: navigation, search
File:Sjws logo.png
Developer(s) Thomas Rudin
Stable release 1.1 / September 20, 2010 (2010-09-20)
Written in Java
Operating system Cross-platform (JVM)
Type Web server
License GPL 3.0

SJWS is a small Java-based HTTP server. SJWS is free software licensed under the GPL 3.0. The Main focus is for embedded Java applications, where a Jetty- or Tomcat-Server is too complicated to deploy.

Supported Content[edit]

SJWS can host every readable resource and provide static and dynamic Web-Content. The dynamic Content is transparent to Java (mapped POJO's).


The Content accessed with a HTTP-Client has the same Structure as the Java-Class-Tree. For Example: A Server running with the Path "/webserver/htdocs" will map all Classes and Resources to the Web-Root-Directory "/".

Dynamic Page[edit]

Dynamic Pages can be created programmatic in the Java Source-Code:

public class List

	public String myList;

	public Object doGet()
		Html html = new Html();
		Body body = new Body();
		Head head = new Head();

		head.add(new StylesheetReference("css/main.css"));

				new Center()
				.add(new H2("Select-List"))
				.add(new BR())
				.add(new Form().setAction(this)
						.add(new Select().setName("myList")
								.add(new Option().setValue("opt1").add("Option1"))
								.add(new Option().setValue("opt2").add("Option2"))
								.add(new Option().setValue("opt3").add("Option3"))
								.add(new Option().setValue("opt4").add("Option4"))
						.add(new InputSubmit().setValue("SAVE"))

		if (myList != null)
			body.add(new H3("You selected: " + myList));

		html.add(head, body);
		body.add(new NoScript().add(html.getObjectStack()));
		return html;


Embedded Dynamic Content[edit]

Dynamic Content can be indirectly accessed with the Java-HTML-Tag

	<java class="InlineRef"></java>

JSON Support[edit]

JSON-Data Output is supported through Annotations:

public class Data

	public Date myDate = new Date();

	public Object entry()
		return JsonUtils.makeJson(this);



The Example shows how to instantiate, start and stop the Server:

public static void main(String[] args) throws IOException
	/* Start server (you just need this one line and the .start() ) */
	server = new SJWServer("/example/htdocs", 8080);
	/* Register Hook-Interface to watch the Server (optional) */
	server.setHook(new Main());
	/* Start server */
	/* Stdout */
	System.out.println("Webserver started @");
	System.out.println("Press <Enter> to stop");
	/* Wait for enter-key */;
	/* Stop Server (optional?) */
	/* Display some stats */
	System.out.println("Server stopped");
	System.out.println("Rx: " + server.getRxBytes());
	System.out.println("Tx: " + server.getTxBytes());

See also[edit]


External links[edit]