A web.xml configuration file for building and testing Dynamic Web pages

Source: Internet
Author: User
Tags html page java web

This article supporting source code

Overview

Wicket is the Java WEB development framework that was recently enabled. It is an open source, lightweight, component-based framework that lets Wicket quickly stand out from the common methods of developing WEB applications. Wicket seeks to clearly define the role lines between HTML page designers and Java developers by supporting templates based on pure HTML, which can be built with any WYSIWYG HTML design tool and can be dynamically characterized by a slight modification.

Like other frameworks, Wicket is built on the servlet API of Sun Microsystems. However, unlike other frameworks based on the Model-view-controller (MVC) model, such as Struts, Wicket allows you to escape from the task of processing request/response objects, which are inherent in technologies such as servlet. With these tasks removed, Wicket lets you focus more on your application's business logic.

As a Wicket developer, you should consider building stateful reusable components rather than building a controller to handle request/response objects and also worrying about multithreading issues. Instead of building a controller or action class, you create a page, place components on the page, and then define how each component responds to user input.

HelloWorld sample

To really show the simplicity of using Wicket to develop web-based applications, you might want to develop a simple "Hello world" example. Developing a dynamic page in Wicket usually involves only creating the following two artifacts:

HTML templates

Java page Classes

Note: You must ensure that the actual HTML file and page class names are the same (for example, helloworld.html and Helloworld.java) and both are in the same position on the CLASSPATH. It is also best to place the two in the same directory.

HTML Template (helloworld.html)

The template file for the HelloWorld sample is shown in Listing 1.

Listing 1. Helloworld.html

<body bgcolor="#FFCC00">
<H1 align="center">
<span wicket:id="message">Hello World Using Wicket!</span>
</H1>
</body>

To make a Dynamic Web page, you need to determine the dynamic part of the page and tell wicket to use the component to render these parts. In Listing 1, I wanted to get a dynamic message, so I used the span element to mark the component, using the Wicket:id attribute to label the component.

Java Page class (Helloworld.java)

Listing 2 shows the page class for the Helloworld.java sample.

Listing 2. Helloworld.java

package myPackage;
import wicket.markup.html.WebPage;
import wicket.markup.html.basic.Label;
public class HelloWorld extends WebPage
{
  public HelloWorld()
  {
   add(new Label("message", "Hello World using Wicket!!"));
  }
}

The ID of the label component in the Page class ("message") must match the Wicket ID (wicket:id= "message") of this element in the template file. The Wicket Java Page class contains all the dynamic behavior of a Web page. There is a one-to-one relationship between the HTML template and the page class.

Finally, you need to create a Application object that is the starting point when the application is loaded by the Web container, and where it is set up and configured for application initialization. For example, you can define the application's home page by overwriting the Gethomepage () method and returning the page class corresponding to the application's home page, as shown in Listing 3.

Listing 3. Helloworldapplication.java

package myPackage;
import wicket.protocol.http.WebApplication;
public class HelloWorldApplication extends WebApplication {
  protected void init() {
  }
  public Class getHomePage() {
   return HelloWorld.class;
  }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.