Wicket是什么

Wicket一个开发Java Web应用程序框架。

它使得开发web应用程序变得easy而轻松。

Wicket利用一个POJO data beans组件使得它能够与不论什么持久层技术相结合。

Wicket使用原生的HTML元素,通过标签<wicket:id>声明为特殊的控件,在后台使用java程序控制这些控件。

Wicket最大的长处就是把视图层和控制层进行了分离。

Java version

这里我用的是Apache Wicket 7.x版本号,所以JDK最低版本号是1.7(博主在用JDK1.7发现缺少java.util.concurrent.ConcurrentLinkedDeque。所以改为JDK1.8)

Servlet API

在这我们须要使用最低servlet3.X版本号

pom.xml配置文件

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ztz.wicket</groupId>
<artifactId>wicket</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-request</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-util</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1-b08</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

在这里我想说明wicket中 全部的组件页面是通过java类相应的 ,也就是说我有一个HelloWorld页面 页面 那么就有一个HelloWorld.java类 并且默认必须在同一文件夹(包)下 当然这是能够自己配置的 ,正是由于如此所以须要在maven的pom增加资源的引入。在build中增加该xml。

		<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>

项目结构是:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

上面们说了。wicket是通过类来代表页面。所以HelloWorld.java与HelloWorld.html对应。

页面用对应标签引用类比如wicket 我们往加入注入一个标签类页面用对应标签引用类比如wicket 我们往加入注入一个标签类

add(new Label("message","Hello world----wicket"));

那么页面我们能够这么写<span wicket:id="message"></span>

以下我们来说下详细实现:

代表web项目的项目 是WebApplication 该类能获得项目上下文 servlet相关 ,同一时候也是一个apache wicket初始化相关 能获得apache wicket这个项目中各个组件部分。继承该类 就类似于实现WebApplicationInitializer接口一样 。该类必须实现getHomePage 方法以下是我写的一个类。

package cn.ztz.application;

import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
/**
* @author azhong
* @version 1.0
* 2015-08-06 22:44:44
*
*/
public class HelloWorldApplication extends WebApplication { @Override
public Class<? extends Page> getHomePage() {
return HelloWorld.class;
} }
package cn.ztz.application;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
/**
* @author azhong
* @version 1.0
* 2015-08-06 22:46:34
*
*/
public class HelloWorld extends WebPage {
public HelloWorld(){
add(new Label("message","Hello world----wicket"));
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello Wicket demo</title>
</head>
<body>
<span wicket:id="message">
这是标签显示,当后台启动应用,应用通过HelloWorld.class能够在HelloWorld.class处理好相关数据 ,
然后通过label类 把属性注入到该页面 该页面通过wicket:id引用
</span>
</body>
</html>

以下我们来配置web.xml相关过滤器:

	<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>cn.ztz.application.HelloWorldApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>HelloWorldApplication</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

启动项目,在浏览器请求:

hello world就说到这里 ,或许大家认为比較奇怪吧,HelloWorld.class 与HelloWorld.html放在一起 ,下一集还有一种配置能够用曾经习惯。

PS:转载注明出处,谢谢。

apache wicket 7.X之HelloWorld的更多相关文章

  1. Meet Apache Wicket

    第一次接触Wicket,如此多的内容是文字,的原贴,希望大家指正 Meet Apache Wicket By JonathanLocke, original author of Wicket 乔纳森· ...

  2. apache开源项目 -- Wicket

    [infoq] Apache Wicket是一个功能强大.基于组件的轻量级Web应用框架,能将展现和业务逻辑很好地分离开来.你能用它创建易于测试.调试和支持的高质量Web 2.0应用.假设其他团队交付 ...

  3. Wicket实战(二)hello world

    上次的博文Wicket实战(一)概述中给大家简介了一下关于Wicket的概念性内容,今天我们完毕第一个Wicket实例-Hello World! 1.Hello World原版        在Wic ...

  4. Apache Nutch v2.3 发布,Java实现的网络爬虫

    http://www.oschina.net/news/59287/apache-nutch-2-3 Apache Nutch v2.3已经发布了,建议所有使用2.X系列的用户和开发人员升级到这个版本 ...

  5. Apache CXF实现Web Service(1)——不借助重量级Web容器和Spring实现一个纯的JAX-WS web service

    废话少说,先在Eclipse中新建一个Java Project (可以不是WTP的Dynamic Web Project) 选择Java Project 再看pom.xml 我们使用cxf 3.1.4 ...

  6. 使用maven在netbeans下构建wicket项目

    在netbeans下构建wicket项目,网上流传较多的方法是直接使用netbeans的wicket插件,这种方法虽然简单,但是依赖的wicket版本较老,更新较慢,并且很容易与其他第三方库不兼容.使 ...

  7. How to setup Wicket Examples in Eclipse

    Wicket examples is a good place to learn Apache Wicket by examples, and a must reference site for ne ...

  8. Wicket Hello World Example

    A simple hello world example in Wicket, show the basic structure of Wicket web application. Tools an ...

  9. Apache 项目列表功能分类便于技术选型

    big-data (49):  Apache Accumulo  Apache Airavata  Apache Ambari  Apache Apex  Apache Avro  Apache Be ...

随机推荐

  1. OpenJDK源码研究笔记(六)--观察者模式工具类(Observer和Observable)和应用示例

    本文主要讲解OpenJDK观察者模式的2个工具类,java.util.Observer观察者接口,java.util.Observable被观察者基类. 然后,给出了一个常见的观察者应用示例. Obs ...

  2. 彻底解决lazarus安装组件后烦人的编译时单元找不到的问题!

    以安装indy为例 1/下载组件包, http://www.indyproject.org/Sockets/fpc/indy-10.2.0.3.zip 2/爆开放于C:\lazarus\compone ...

  3. 特性Attibute定义和使用

    1.定义特性 [AttributeUsage(AttributeTargets.Class,AllowMultiple = false,Inherited = false)] public class ...

  4. POJ 1682 DP

    原创: http://www.cnblogs.com/proverbs/archive/2012/10/03/2711151.html 超高仿: http://blog.csdn.net/mars_c ...

  5. UltraEdit Companion Utility

    UltraEdit Companion Utility 配色组件 http://www.danielwmoore.com/extras/index.php?action=downloads;sa=vi ...

  6. Coderfroces 862 C. Mahmoud and Ehab and the xor

    C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...

  7. 应对加密js的三种方法

    经常遇到网页在登录后会对用户输入的帐号和密码通过js进行加密,导致模拟登录这类网站时受到阻碍 这里小记一下当前解决该问题的三种方法 1.利用python实现js同等加密. 2.利用selenium模拟 ...

  8. Vue常见面试题汇总

    Vue框架常见面试题   1.active-class是哪个组件的属性?嵌套路由怎么定义? 答:vue-router模块的router-link组件. 2.怎么定义vue-router的动态路由?怎么 ...

  9. Linux运维管理的必备工具

    一.统一账号管理 1.LDAP 统一管理各种平台帐号和密码,包括但不限于各种操作系统(Windows.Linux),Linux系统sudo集成,系统用户分组,主机登入限制等:可与Apache,HTTP ...

  10. CentOS 7上安装gitlab-runner

    1.yum install gitlab-runner -y 2.Registering Runners a.Run the following command: gitlab-runner regi ...