安装或设置

我的第一个 Wicket 设置,应用程序在主屏幕上显示 Hello World:

import org.apache.wicket.protocol.http.WebApplication;
public class HelloWorldApplication extends WebApplication {
    
    public HelloWorldApplication() {
    }
    
    @Override
    public Class getHomePage() {
        return HelloWorld.class;
    }
}

HelloWorld.java

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

HelloWorld.html 的

<html>
   <body>
       <span wicket:id="message">Message goes here</span>
    </body>
</html>

web.xml 中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <display-name>My first Wicket App</display-name>
    <filter>
        <filter-name>HelloWorldApplication</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
          <param-name>applicationClassName</param-name>
          <param-value>org.apache.wicket.examples.helloworld.HelloWorldApplication</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HelloWorldApplication</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

pom.xml

    <dependency>
        <groupId>org.apache.wicket</groupId>
        <artifactId>wicket-core</artifactId>
        <version>${wicket.version}</version>
    </dependency>