Solon详解(十)- 怎么用 Solon 开发基于 undertow jsp tld 的项目?
Solon详解系列文章:
Solon详解(一)- 快速入门
Solon详解(二)- Solon的核心
Solon详解(三)- Solon的web开发
Solon详解(四)- Solon的事务传播机制
Solon详解(五)- Solon扩展机制之Solon Plugin
Solon详解(六)- Solon的校验扩展框架使用与扩展
Solon详解(七)- Solon Ioc 的注解对比Spring及JSR330
Solon详解(八)- Solon的缓存框架使用和定制
Solon详解(九)- 渲染控制之定制统一的接口输出
Solon
开发 jsp
项目是非常简单的,只要改用 jetty
启动器 或者 undertow
启动器,其它也没特别之处了。此文用 undertow + jsp + tld
这个套路搞一把:
一、 开始Meven配置走起
用solon 做 undertow + jsp 的开发;只需要配置一下 meven 即可(不需要其它的额外处理或启用)
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>1.0.40</version>
</parent>
<dependencies>
<!-- 添加 solon web 开发包 -->
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-web</artifactId>
<type>pom</type>
<exclusions>
<!-- 排除默认的 jlhttp 启动器 -->
<exclusion>
<groupId>org.noear</groupId>
<artifactId>solon.boot.jlhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 添加 undertow 启动器 -->
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.boot.undertow</artifactId>
</dependency>
<!-- 添加 undertow jsp 扩展支持包 -->
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.extend.undertow.jsp</artifactId>
</dependency>
<!-- 添加 jsp 视图渲染器(可以添加一堆别的view插件) -->
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.view.jsp</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
二、 其它代码和平常开发就差不多了
//资源路径说明(不用配置)
resources/application.properties(或 application.yml) 为应用配置文件
resources/static/ 为静态文件根目标
resources/WEB-INF/view/ 为视图文件根目标(支持多视图共存)
//调试模式:
启动参数添加:-deubg=1
- 添加个控制器
src/main/java/webapp/controller/HelloworldController.java
@XController
public class HelloworldController {
//这里注入个配置
@XInject("${custom.user}")
protected String user;
@XMapping("/helloworld")
public ModelAndView helloworld(XContext ctx){
UserModel m = new UserModel();
m.setId(10);
m.setName("刘之西东");
m.setSex(1);
ModelAndView vm = new ModelAndView("helloworld.jsp"); //如果是ftl模板,把后缀改为:.ftl 即可
vm.put("title","demo");
vm.put("message","hello world!");
vm.put("m",m);
vm.put("user", user);
vm.put("ctx",ctx);
return vm;
}
}
- 再搞个自定义标签
src/main/java/webapp/widget/FooterTag.java
(对jsp来说,这个演示很重要)
public class FooterTag extends TagSupport {
@Override
public int doStartTag() throws JspException {
try {
String path = XContext.current().path();
//当前视图path
StringBuffer sb = new StringBuffer();
sb.append("<footer>");
sb.append("我是自定义标签,FooterTag;当前path=").append(path);
sb.append("</footer>");
pageContext.getOut().write(sb.toString());
}
catch (Exception e){
e.printStackTrace();
}
return super.doStartTag();
}
@Override
public int doEndTag() throws JspException {
return super.doEndTag();
}
}
- 加tld描述文件
src/main/resources/WEB-INF/tags.tld
(位置别乱改,就放这儿...)
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<description>自定义标签库</description>
<tlib-version>1.1</tlib-version>
<short-name>ct</short-name>
<uri>/tags</uri>
<tag>
<name>footer</name>
<tag-class>webapp.widget.FooterTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
- 视图
src/main/resources/WEB-INF/view/helloworld.jsp
<%@ page import="java.util.Random" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="ct" uri="/tags" %>
<html>
<head>
<title>${title}</title>
</head>
<body>
<div>
context path: ${ctx.path()}
</div>
<div>
properties: custom.user :${user}
</div>
<main>
${m.name} : ${message} (我想<a href="/jinjin.htm">静静</a>)
</main>
<ct:footer/>
</body>
</html>
三、 疑问
一路上没有web.xml ? 是的,没有。
四、 源码
源码:demo05.solon_mvc_undertow_jsp
Solon详解(十)- 怎么用 Solon 开发基于 undertow jsp tld 的项目?的更多相关文章
- 怎么用 Solon 开发基于 undertow jsp tld 的项目?
Solon 开发 jsp 还是简单的,可以有 jetty 启动器 或者 undertow 启动器.此文用 undertow + jsp + tld 这个套路搞一把: 一. 开始Meven配置走起 用s ...
- Solon详解(三)- Solon的web开发
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Springboot mini - Solon详解(三)- Solon的web开发
Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...
- Solon详解(六)- Solon的校验扩展框架使用与扩展
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Solon详解(二)- Solon的核心
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Solon详解(七)- Solon Ioc 的注解对比Spring及JSR330
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Solon详解(八)- Solon的缓存框架使用和定制
Solon详解系列文章: Solon详解(一)- 快速入门 Solon详解(二)- Solon的核心 Solon详解(三)- Solon的web开发 Solon详解(四)- Solon的事务传播机制 ...
- Springboot mini - Solon详解(四)- Solon的事务传播机制
Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...
- Springboot mini - Solon详解(二)- Solon的核心
Springboot min -Solon 详解系列文章: Springboot mini - Solon详解(一)- 快速入门 Springboot mini - Solon详解(二)- Solon ...
随机推荐
- Laravel Reponse 响应客户端
Laravel Response 响应客户端 本篇文章逻辑较长,只说明和响应生命周期相关的必要代码. 本文主要内容顺序为: 1.执行上文管道中的then方法指定的闭包,路由的分发 2.在路由器中(Ro ...
- wampserver64 apache2.4版本局域网互相访问总结
wampserver64 apache2.4版本局域网互相访问总结 背景:在我的电脑上给算法组开发了一个工具,需要在局域网环境下其他同事都能访问到,搞了一下午终于搞定,于是整理了这篇文档,给其他同行 ...
- 趣味vi:Do you love me?
看到网上有很多这样的小趣味exe,自己用labview也做了一个,可能有很多bug,马马虎虎能用,大家可以发给自己滴那个人,哈哈哈.源码vi和exe文件都在链接中https://files.cnblo ...
- Linux下Vim常用操作
linux下Vim的常用操作 linux 首先\(ctrl+Alt+t\)打开小框框 \(./\):相当于手机上的\(home\)键 \(ls\):当前文件夹的东东 \(mkdir\) ...
- UniRapidJson
https://github.com/takezoh/UniRapidJson 如何编译安卓 cd ~/UniRapidJson/build/android make 生成的so可以在 /Users/ ...
- beautifulsoup教程
beautifulsoup教程 BeautifulSoup4是爬虫必学的技能.BeautifulSoup最主要的功能是从网页抓取数据,Beautiful Soup自动将输入文档转换为Unicode编码 ...
- 利用css3 transform实现一个时钟
transform:rotate(1deg) <!DOCTYPE html> <html lang="en"> <head> <meta ...
- 干Java这一行,应该怎样提升自己?
前段时间,字节跳动在阿里巴巴的大本营杭州悄悄的建立一个研发中心,最近在疯狂招人. 相信最近一段时间,杭州的很多的互联网公司的开发人员都接到过猎头的电话.据了解,字节跳动杭州研发中心主要负责字节跳动新增 ...
- linux6.4内核由2.6升级成3.6
安装CentOS 6.4之后,内核默认是2.6.32.由于docker需要3.0以上的内核,所以需要对内核进行升级. 1. 安装必要组件# yum -y install ncurses-devel # ...
- selenium中Xpath标签定位和cssSelectors定位(优先用cssSelectors)
二者的区别:xpath 支持角标定位,cssselector不支持 1.XPath是XML的路径语言,通俗一点讲就是通过元素的路径来查找到这个标签元素. xpath支持属性定位,无论是默认属性还是自定 ...