apache wicket 7.X之HelloWorld
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的更多相关文章
- Meet Apache Wicket
第一次接触Wicket,如此多的内容是文字,的原贴,希望大家指正 Meet Apache Wicket By JonathanLocke, original author of Wicket 乔纳森· ...
- apache开源项目 -- Wicket
[infoq] Apache Wicket是一个功能强大.基于组件的轻量级Web应用框架,能将展现和业务逻辑很好地分离开来.你能用它创建易于测试.调试和支持的高质量Web 2.0应用.假设其他团队交付 ...
- Wicket实战(二)hello world
上次的博文Wicket实战(一)概述中给大家简介了一下关于Wicket的概念性内容,今天我们完毕第一个Wicket实例-Hello World! 1.Hello World原版 在Wic ...
- Apache Nutch v2.3 发布,Java实现的网络爬虫
http://www.oschina.net/news/59287/apache-nutch-2-3 Apache Nutch v2.3已经发布了,建议所有使用2.X系列的用户和开发人员升级到这个版本 ...
- 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 ...
- 使用maven在netbeans下构建wicket项目
在netbeans下构建wicket项目,网上流传较多的方法是直接使用netbeans的wicket插件,这种方法虽然简单,但是依赖的wicket版本较老,更新较慢,并且很容易与其他第三方库不兼容.使 ...
- 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 ...
- Wicket Hello World Example
A simple hello world example in Wicket, show the basic structure of Wicket web application. Tools an ...
- Apache 项目列表功能分类便于技术选型
big-data (49): Apache Accumulo Apache Airavata Apache Ambari Apache Apex Apache Avro Apache Be ...
随机推荐
- [洛谷P3929]SAC E#1 - 一道神题 Sequence1
题目大意:给你一串数列,问你能否改变1个数或不改,使它变成波动数列? 一个长度为n的波动数列满足对于任何i(1 <= i < n),均有: a[2i-1] <= a[2i] 且 a[ ...
- [NOIP2015提高组]运输计划
题目:BZOJ4326.洛谷P2680.Vijos P1983.UOJ#150.codevs4632.codevs5440. 题目大意:有一棵带权树,有一些运输计划,第i个运输计划从ai到bi,耗时为 ...
- vector容器的实现
简单实现了构造.析构.push_back.pop_back.operator=.operator[].clear等函数 template<class T> class my_vector ...
- C. Diverse Permutation(Codeforces Round #275(div2)
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Ext4.0 经常使用代码整理(一)
一:经常使用工具条上的定义 // 工具条 var toolbar = Ext.create("Ext.Toolbar", { items : [ yearC ...
- vue16 自定义键盘属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- php如何截取出视频中的指定帧作为图片
php如何截取出视频中的指定帧作为图片 一.总结 一句话总结:截取视频指定帧为图片,php ffmpeg扩展已经完美实现,并且php ffmpeg是开源的 二.php如何截取出视频中的指定帧作为图片 ...
- js易错点总结及 常见面试的坑
最近在研究Javascript发现了其中一些比较灵异的事情.有点让人感到无语比如: var arr = [], arr2 = {}; console.log(typeof(arr) === typeo ...
- BZOJ 1103 DFS序+线段树
思路: 先搞出来DFS序 进入这个点 +1 出这个点 -1 线段树维护前缀和 (因为还要修改) 搞定 修改的时候只修改底下节点就OK了 (边权–>点权 不多说) //By SiriusRen # ...
- Atcoder B - Moderate Differences
http://agc017.contest.atcoder.jp/tasks/agc017_b B - Moderate Differences Time limit : 2sec / Memory ...