Velocity 的应用示例

GprMax正演模拟:为什么你的反射波‘消失’了?可能是直达波在捣鬼(附Python后处理脚本) 本文深入探讨了GprMax正演模拟中反射波信号被直达波淹没的现象,并提供了Python后处理脚本的实战指南。通过时域置零、自适应增益控制、频域滤波等多种技术,有效增强反射波信号,帮助用户解决探地雷达模拟中的常见问题。文章还包含详细的代码示例和效果评估方法,适合GPR数据处理的研究人员和工程师参考。 阅读详情
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> Velocity 的应用示例  关键字:Java, JSP, Servlet, template, 模板, Apache, Jakarta, Velocity 读者要求:了解 Java Servlet 基本概念  Velocity 是一个基于 Java 的通用模板工具,来自于 jakarta.apache.org 。 Velocity 的介绍请参考 Velocity -- Java Web 开发新技术。这里是它的一个应用示例。 这个例子参照了 PHP-Nuke 的结构, 即所有 HTTP 请求都以 http://www.some.com/xxx/Modules?name=xxx&arg1=xxx&bbb=xxx 的形式进行处理。例子中所有文件都是 .java 和 .html , 没有其他特殊的文件格式。除了 Modules.java 是 Java Servlet, 其余的 .java 文件都是普通的 Java Class. 所有 HTTP 请求都通过 Modules.java 处理。Modules.java 通过 Velocity 加载 Modules.htm。 Modules.htm 有页头,页脚,页左导航链接,页中内容几个部分。其中页头广告、页中内容是变化部分。页头广告由 Modules.java 处理,页中内容部分由 Modules.java dispatch 到子页面类处理。 1) Modules.java import javax.servlet.*; import javax.servlet.http.*; import org.apache.velocity.*; import org.apache.velocity.context.*; import org.apache.velocity.exception.*; import org.apache.velocity.servlet.*; import commontools.*; public class Modules   extends VelocityServlet {   public Template handleRequest(HttpServletRequest request,                  HttpServletResponse response,                  Context context) {     //init     response.setContentType("text/html; charset=UTF-8");     response.setCharacterEncoding("utf-8");     //prepare function page     ProcessSubPage page = null;     ProcessSubPage mainPage = new HomeSubPage();     String requestFunctionName = (String) request.getParameter("name");     boolean logined = false;     String loginaccount = (String) request.getSession(true).getAttribute(       "loginaccount");     if (loginaccount != null) {       logined = true;     }     //default page is mainpage     page = mainPage;     if (requestFunctionName == null||requestFunctionName.equalsIgnoreCase("home")) {       page = mainPage;     }     //no login , can use these page     else if (requestFunctionName.equalsIgnoreCase("login")) {       page = new LoginProcessSubPage();     }     else if (requestFunctionName.equalsIgnoreCase("ChangePassword")) {       page = new ChangePasswordSubPage();     }     else if (requestFunctionName.equalsIgnoreCase("ForgetPassword")) {       page = new ForgetPassword();     }     else if (requestFunctionName.equalsIgnoreCase("about")) {       page = new AboutSubPage();     }     else if (requestFunctionName.equalsIgnoreCase("contact")) {       page = new ContactSubPage();     }     //for other page, need login first     else if (logined == false) {       page = new LoginProcessSubPage();     }     else if (requestFunctionName.equalsIgnoreCase("listProgram")) {       page = new ListTransactionProgramSubPage();     }     else if (requestFunctionName.equalsIgnoreCase(       "ViewProgramItem")) {       page = new ViewTransactionProgramItemSubPage();     }     else if (requestFunctionName.equalsIgnoreCase(       "UpdateProgramObjStatus")) {       page = new UpdateTransactionProgramObjStatusSubPage();     }     else if (requestFunctionName.equalsIgnoreCase(       "Search")) {       page = new SearchSubPage();     }     //check if this is administrator     else if (Utilities.isAdministratorLogined(request)) {       //Utilities.debugPrintln("isAdministratorLogined : true");       if (requestFunctionName.equalsIgnoreCase("usermanagement")) {         page = new UserManagementSubPage();       }       else if (requestFunctionName.equalsIgnoreCase(         "UploadFiles")) {         page = new UploadFilesSubPage();       }       else if (requestFunctionName.equalsIgnoreCase(         "DownloadFile")) {         page = new DownloadFileSubPage();       }       else if (requestFunctionName.equalsIgnoreCase(         "Report")) {         page = new ReportSubPage();       }     }     else {       //no right to access.       //Utilities.debugPrintln("isAdministratorLogined : false");       page = null;     }     //Utilities.debugPrintln("page : " page.getClass().getName());     if(page != null){       context.put("function_page",             page.getHtml(this, request, response, context));     }else{       String msg = "Sorry, this module is for administrator only.You are not administrator.";       context.put("function_page",msg);     }          context.put("page_header",getPageHeaderHTML());     context.put("page_footer",getPageFooterHTML());     Template template = null;     try {       template = getTemplate("/templates/Modules.htm"); //good     }     catch (ResourceNotFoundException rnfe) {       Utilities.debugPrintln("ResourceNotFoundException 2");       rnfe.printStackTrace();     }     catch (ParseErrorException pee) {       Utilities.debugPrintln("ParseErrorException2 " pee.getMessage());     }     catch (Exception e) {       Utilities.debugPrintln("Exception2 " e.getMessage());     }     return template;   }   /**    * Loads the configuration information and returns that information as a Properties, e    * which will be used to initializ the Velocity runtime.    */   protected java.util.Properties loadConfiguration(ServletConfig config) throws     java.io.IOException, java.io.FileNotFoundException {     return Utilities.initServletEnvironment(this);   } } 2) ProcessSubPage.java , 比较简单,只定义了一个函数接口 getHtml import javax.servlet.http.*; import org.apache.velocity.context.*; import org.apache.velocity.servlet.*; import commontools.*; public abstract class ProcessSubPage implements java.io.Serializable {   public ProcessSubPage() {   }   public String getHtml(VelocityServlet servlet, HttpServletRequest request,              HttpServletResponse response,              Context context) {     Utilities.debugPrintln(       "you need to override this method in sub class of ProcessSubPage:"        this.getClass().getName());     return "Sorry, this module not finish yet.";   } } 他的 .java 文件基本上是 ProcessSubPage 的子类和一些工具类。 ProcessSubPage 的子类基本上都是一样的流程, 用类似 context.put("page_footer",getPageFooterHTML()); 的写法置换 .html 中的可变部分即可。如果没有可变部分,完全是静态网页,比如 AboutSubPage, 就更简单。 3) AboutSubPage.java import org.apache.velocity.servlet.VelocityServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.velocity.context.Context; public class AboutSubPage extends ProcessSubPage {   public AboutSubPage() {   }   public String getHtml(VelocityServlet servlet, HttpServletRequest request,              HttpServletResponse response, Context context) {     //prepare data     //context.put("xxx","xxxx");                            Template template = null;     String fileName = "About.htm";     try {       template = servlet.getTemplate(fileName);       StringWriter sw = new StringWriter();       template.merge(context, sw);       return sw.toString();     }     catch (Exception ex) {       return "error get template " fileName " " ex.getMessage();     }   } } 其他 ProcessSubPage 的子类如上面基本类似,只不过会多了一些 context.put("xxx","xxxx") 的语句。 通过以上的例子,我们可以看到,使用 Velocity Servlet , 所有的代码为: 1 个 java serverlet m 个 java class n 个 Html 文件。 这里是用了集中处理,然后分发(dispatch)的机制。不用担心用户在没有登陆的情况下访问某些页面。用户验证,页眉页脚包含都只写一次,易于编写、修改和维护。代码比较简洁,并且很容易加上自己的页面缓冲功能。可以随意将某个页面的 html 在内存中保存起来,缓存几分钟,实现页面缓冲功能。成功、出错页面也可以用同样的代码封装成函数,通过参数将 Message/Title 传入即可。 因为 Java 代码与 Html 代码完全在不同的文件中,美工与java代码人员可以很好的分工,每个人修改自己熟悉的文件,基本上不需要花时间做协调工作。而用 JSP, 美工与java代码人员共同修改维护 .jsp 文件,麻烦多多,噩梦多多。而且这里没有用 xml ,说实话,懂 xml/xls 之类的人只占懂 Java 程序员中的几分之一,人员不好找。 因为所有 java 代码人员写的都是标准 Java 程序,可以用任何 Java 编辑器,调试器,因此开发速度也会大大提高。美工写的是标准 Html 文件,没有 xml, 对于他们也很熟悉,速度也很快。并且,当需要网站改版的时候,只要美工把 html 文件重新修饰排版即可,完全不用改动一句 java 代码。 爽死了!! 4) 工具类 Utilities.java import java.io.*; import java.sql.*; import java.text.*; import java.util.*; import java.util.Date; import javax.naming.*; import javax.servlet.*; import javax.servlet.http.*; import org.apache.velocity.*; import org.apache.velocity.app.*; import org.apache.velocity.context.Context; import org.apache.velocity.servlet.*; public class Utilities {   private static Properties m_servletConfig = null;   private Utilities() {   }   static {     initJavaMail();   }   public static void debugPrintln(Object o) {     String msg = "proj debug message at " getNowTimeString()       " ------------- ";     System.err.println(msg o);   }   public static Properties initServletEnvironment(VelocityServlet v) {     // init only once     if (m_servletConfig != null) {       return m_servletConfig;     }     //debugPrintln("initServletEnvironment....");     try {       /*        * call the overridable method to allow the        * derived classes a shot at altering the configuration        * before initializing Runtime        */       Properties p = new Properties();       ServletConfig config = v.getServletConfig();       // Set the Velocity.FILE_RESOURCE_LOADED_PATH property       // to the root directory of the context.       String path = config.getServletContext().getRealPath("/");       //debugPrintln("real path of / is : " path);       p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);       // Set the Velocity.RUNTIME_LOG property to be the file       // velocity.log relative to the root directory       // of the context.       p.setProperty(Velocity.RUNTIME_LOG, path              "velocity.log"); // Return the Properties object. //return p;       Velocity.init(p);       m_servletConfig = p;       return p;     }     catch (Exception e) {       debugPrintln(e.getMessage());       //throw new ServletException("Error initializing Velocity: " e);     }     return null;     //this.getServletContext().getRealPath("/");   }   private static void initJavaMail() {   }   public static Connection getDatabaseConnection() {     Connection con = null;     try {       InitialContext initCtx = new InitialContext();       javax.naming.Context context = (javax.naming.Context) initCtx.         lookup("java:comp/env");       javax.sql.DataSource ds = (javax.sql.DataSource) context.lookup(         "jdbc/TestDB");       //Utilities.debugPrintln("ds = " ds);       con = ds.getConnection();     }     catch (Exception e) {       Utilities.debugPrintln("Exception = " e.getMessage());       return null;     }     //Utilities.debugPrintln("con = " con);     return con;   }   public static java.sql.ResultSet excuteDbQuery(Connection con, String sql,     Object[] parameters) {     //Exception err = null;     //Utilities.debugPrintln("excuteDbQuery" parameters[0] " ,sql=" sql);     try {       java.sql.PreparedStatement ps = con.prepareStatement(sql);       for (int i = 0; i < parameters.length; i ) {         processParameter(ps, i 1, parameters[i]);       }       return ps.executeQuery();     }     catch (Exception e) {       //Utilities.debugPrintln(e.getMessage());       e.printStackTrace();     }     return null;   }   public static void excuteDbUpdate(String sql, Object[] parameters) {     Connection con = Utilities.getDatabaseConnection();     excuteDbUpdate(con, sql, parameters);     closeDbConnection(con);   }   public static void excuteDbUpdate(Connection con, String sql,                    Object[] parameters) {     Exception err = null;     try {       java.sql.PreparedStatement ps = con.prepareStatement(sql);       for (int i = 0; i < parameters.length; i ) {         processParameter(ps, i 1, parameters[i]);       }       ps.execute();     }     catch (Exception e) {       err = e;       //Utilities.debugPrintln(err.getMessage());       e.printStackTrace();     }   }   private static void processParameter(java.sql.PreparedStatement ps,                      int index, Object parameter) {     try {       if (parameter instanceof String) {         ps.setString(index, (String) parameter);       }       else {         ps.setObject(index, parameter);       }     }     catch (Exception e) {       //Utilities.debugPrintln(e.getMessage());       e.printStackTrace();     }   }   public static void closeDbConnection(java.sql.Connection con) {     try {       con.close();     }     catch (Exception e) {       Utilities.debugPrintln(e.getMessage());     }   }   public static String getResultPage(     String title, String message, String jumpLink,     VelocityServlet servlet, HttpServletRequest request,     HttpServletResponse response, Context context) {     Template template = null;     context.put("MessageTitle", title);     context.put("ResultMessage", message);     context.put("JumpLink", jumpLink);     try {       template = servlet.getTemplate(         "/templates/Message.htm");       StringWriter sw = new StringWriter();       template.merge(context, sw);       return sw.toString();     }     catch (Exception ex) {       return "error get template Message.htm " ex.getMessage();     }   }   public static String mergeTemplate(String fileName, VelocityServlet servlet,                     Context context) {     Template template = null;     try {       template = servlet.getTemplate(fileName);       StringWriter sw = new StringWriter();       template.merge(context, sw);       return sw.toString();     }     catch (Exception ex) {       return "error get template " fileName " " ex.getMessage();     }   } }
涨姿势|小众建模软件Make human,MakeClothes插件使用详解教程(2) 衣服可以从头开始建模,或者通过改变人体网格或由MakeClothes工具提供的“服装助手”(见下文)来建模。在设计和建模一件衣物时,应该记住两个限制。首先,将服装网格映射到人体网格的算法要求服装网格完全由四面体组成。其次,知道MakeClothes每件衣服只支持一种材料是很重要的。 完成MakeClothes工作流程后,您的HOME / makehuman / v1 / data / clothes中的工具将创建一个新文件夹。该文件夹将采用用户为服装项目提供的唯一名称。该文件夹将填充必要的资源,以使该项目在 阅读详情

相关推荐

newman的使用

Newman是一个基于Node.js的postman命令行工具,用于运行和测试PostmanAPI 请求的集合。它允许用户在命令行环境中执行Postman的JSON文件,从而实现接口自动化测试和持续集成,同时支持用户进行自动化测试、批量执行请求、生成报告等操作。

m0_62825058的博客 1620

Velocity使用示例

本文介绍了Velocity的使用示例

快乐江小鱼的博客 366

Nacos漏洞利用工具V3.0.5实战:从认证绕开到内存马植入的全流程指南

本文详细解析了Nacos漏洞利用工具V3.0.5在实战中的应用,从认证绕开到内存马植入的全流程。文章深入探讨了如何利用Nacos的历史漏洞,如默认口令、认证逻辑绕过、Derby SQL注入及Jraft反序列化,实现权限提升与持久化控制,并提供了防御视角与加固建议,旨在帮助安全人员理解攻击链以加强防护。

h6j7k8l9p0的博客 485

Velocity入门教程一

简介Velocity是一个基于JAVA的模板引擎,使用这个工具你可以很容易地创建和渲染你所要展示的格式化文档。 官网定义: Velocity is a Java-based template engine, a simple and powerful development tool that allows you to easily create and render documents

u014133299的博客 931

【Linux系统】Kdenlive软件多机位同音频视频同步化处理

Kdenlive简介 官网链接:https://kdenlive.org/zh/ 命令行安装: apt-get install kdenlive Kdenlive能够进行多轨道视频编辑,可以使用和调整多条音频、视频轨道。每条轨道可以按需进行单独锁定、静音。 Kdenlive多机位同音频视频同步化处理步骤 1. 新建Kdenlive文件 选择<文件>-<新建>,建立新的kdenlive文件,初始设置为<视频轨:2>,<音频轨:2>。 视.

qq_31550269的博客 1892

Pytorch实用教程:super(MLP,self).__init__()和super().__init__()有什么区别?

在 Python 中,super()函数用于调用父类(超类)的方法。它的使用在继承关系中非常常见,特别是在初始化继承自父类的属性时。在 PyTorch 中,这通常见于初始化nn.Module类的子类。super()的两种调用方式有微妙的差别,但在 Python 3 中常常用来达到同样的目的。这种写法在 Python 2 中非常常见。这里,super()被调用时需要指定当前类名(MLP)和当前实例(self。

若北辰 1029

Velocity示例

[size=xx-large][color=orange][b]Velocity示例[/b][/color][/size] HelloController.java类: [size=medium][b][color=red]示例01:[/color][/b][/size] [code="java"] package com.xiaonei.rose.gettingStarted.con...

mohaiyong的专栏 238

【AI产品思路】用户旅程图与用户全生命周期:到底是什么关系?

用户旅程图(User Journey Map)和用户全生命周期(User Lifecycle)是两种不同的分析框架。用户旅程聚焦单次交易体验的完整过程(如浏览→下单→售后),关注触点、情绪和优化点;而用户生命周期则关注用户与平台的长期关系(从认知到流失),着重提升留存和LTV。两者互为补充:生命周期是时间维度的关系框架,旅程图是行为维度的体验路径。电商运营中,旅程优化改善单次体验,生命周期优化解决长期增长问题,二者结合才能实现体验提升与商业效率的双赢。

qq_25438419的博客 221

一、什么是Velocity及简单示例

1、velocity简介:  velocity是一个java模板引擎技术,任何人可以使用这种简单而又强有力的模板语言去获取java对象。  在使用Velocity进行web开发时,web开发人员和java程序员可以同时根据Model-View-Controller(MVC)模型,进行网站开发,这也意味着web开发人员可以纯粹的专注于创建看起来好看的网页而程序员可专门编写完美的代码。...

aan3237的博客 766

微信小程序 - 实现嵌套H5页面唤起微信支付的实现方案+完整流程源码,微信小程序webview(H5页面)调用微信小程序支付,嵌套h5页面怎么实现小程序支付(Vue2/3移动端H5网页、公众号网页等)

h5嵌入微信小程序微信支付,H5网页嵌入到微信小程序内如何支付,微信小程序webview组件交互,内联h5页面并网页实现微信支付,微信H5页面实现微信小程序支付,微信小程序嵌套webview实现小程序微信支付,小程序中内嵌H5网页支付怎么办,用网页的支付还是小程序的支付?支付没反应,支付报错怎么办,微信小程序内嵌h5,h5调用小程序支付功能解决方案,H5网页cors跨域,真机测试无法唤起支付,无法唤起支付,uniapp微信小程序,h5小程序调用微信支付,微信小程序内嵌H5页面,如何实现微信支付功能,微信小程

🏆 前端领域优质创作者 1万+

uniapp - [全端兼容] 详解实现国际化多语言切换全流程及示例,全部页面中英文多语言随意切换即时生效,语言切换全项目立即变化可自定义新增各国其他语言,uniApp实现中英文语言切换完整源码教程!

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,uniapp多语言实现,uni-app项目使用多语言切换功能,中英文切换,uniapp实现中英文语言切换,uniApp实现国际化多语言切换,中文英文之间的更换,Uniapp使用什么插件能支持多种语言,退出后重启依然能让语言保留,设置可切换中英文,uniapp国际化页面双语/顶部导航双语/根据系统语言双语,标题栏文字原生底部菜单tabbar怎么改,使用vue-i18n国际化多国语言,全平台i18n插件,

🏆 前端领域优质创作者 1万+

Tiny模板引擎(Velocity Plus)应用示例

目录[-]宏的可变参数 Set示例宏定义及其调用示例宏定义及其调用进阶示例宏定义及其调用之嵌套定义Tiny模板中的内容显示Tiny模板之注释Tiny模板引擎强制不解析标记Tiny模板引擎之IFTiny模板语言之循环Tiny模板引擎之布局Tiny模板引擎之调用宏的N种写法Tiny模板引擎之宏默认值Tiny模板引擎之格式严格控制如何快速编写并运行Tiny模板Tiny模板引擎之配套开发工具特性介绍截...

TINY框架 419

SCADA|KingSCADA实现有新报警时声音报警提示

在SCADA项目中有的现场系统比较多,每个调度员可能会一个人盯好多个系统,因此不会一直盯着一个系统,这时候就需要当有新的报警产生时,有报警声音提示,提示调度员查看报警,进行处理。$NewAlarm是一个离散型的变量,是新报警的意思,即当前系统中有新的报警信息产生时,该变量会自动置为1;以上为一最简单的报警提示的实现,实际中可能还会要求语音播报啥啥报警的声音,具体有时间再进行测试。通过创建测试界面,创建一个内存变量,内存变量,配置报警,界面按钮制造报警,测试效果。

做有价值的事,积累有价值的笔记! 1421

Velocity资源

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34033624的博客 180

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Velocity入门之基础语法

1. 变量 (1)变量的定义: #set($name = "hello") 说明:velocity中变量是弱类型的。 当使用#set 指令时,括在双引号中的字面字符串将解析和重新解释,如下所示: #set($directoryRoot = "www" ) #set($templateName = "index.vm" ) #set($template = "$dire...

u011833515的专栏 210

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Velocity实例

Velocity 是一个基于 Java 的通用模板工具,来自于 jakarta.apache.org 。 Velocity 的介绍请参考 Velocity -- Java Web 开发新技术。这里是它的一个应用示例。这个例子参照了 PHP-Nuke 的结构, 即所有 HTTP 请求都以 http://www.some.com/xxx/Modules?name=xxx&arg1=xxx&bbb=xx

joy的专栏 1430

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Velocity 入门之 HelloWorld

Velocity 是如何工作的呢? 虽然大多 Velocity 的应用都是基于 Servlet 的网页制作。但是为了说明 Velocity 的使用,我决定采用更通用的 Java application 来说明它的工作原理。    似乎所有语言教学的开头都是采用 HelloWorld 来作为第一个程序的示例。这里也不例外。  01 package com.mak

caomiao2006的专栏 953

velocity入门示例

<br /><br /> <br />下面是一个简单的实例:<br /> <br />java代码:<br /> <br />package com.ali.vm;<br /> <br />import java.io.StringWriter;<br />import java.math.BigDecimal;<br />import java.util.Date;<br /> <br />import org.apache.velocity.app.VelocityEngine;<br />import

天涯行客 881

Velocity入门到精通(上篇)

Velocity是一个基于Java的模板引擎,可以通过特定的语法获取在java对象的数据 , 填充到模板中,从而实现界面和java代码的分离!Velocity Template Language (VTL) , 是Velocity 中提供的一种模版语言 , 旨在提供最简单和最干净的方法来将动态内容合并到网页中。简单来说VTL可以将程序中的动态数展示到网页中注释非解析内容引用和指令。

我有一张床的博客 2万+

velocity入门(二)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34337381的博客 74
上一篇: 将脚本语言加进你的程序中
下一篇: J2me的基本概念
java169
博客等级 码龄19年 27粉丝 2568原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址