groovy 速学 - 32 - Web 开发
来源:互联网 发布:ubuntu terminal 颜色 编辑:程序博客网 时间:2024/05/04 15:08
目录
- Web开发
- Web上下文
- Groovlet
- 概念
- 简单的 Groovlet
- Groovlet 隐藏对象
- GSP
- 概念
- 简单的 GSP
- 配置运行环境
- IDEA 的配置
- Web开发
摘要
groovlet,gsp
Web开发
Web上下文
要使用 Groovy 开发 Web 程序,首先需要配置上下文,更新 web.xml 文件。
<servlet> <servlet-name>GroovyServlet</servlet-name> <servlet-class>groovy.servlet.GroovyServlet</servlet-class></servlet><servlet> <servlet-name>GroovyTemplate</servlet-name> <servlet-class>groovy.servlet.TemplateServlet</servlet-class></servlet><servlet-mapping> <servlet-name>GroovyServlet</servlet-name> <url-pattern>*.groovy</url-pattern></servlet-mapping><servlet-mapping> <servlet-name>GroovyTemplate</servlet-name> <url-pattern>*.gsp</url-pattern></servlet-mapping>
上述配置定义了以 groovy
结尾的请求都将发送给 groovy.servlet.GroovyServlet
,以 gsp
结尾的请求都将发送给 groovy.servlet.TemplateServlet
Groovlet
概念
Groovlet 以 Servlet 为基础,但是无需继承 HttpServlet,也无需实现 doGet(),doPost() 方法。
实际上使用 Groovlet 可以像脚本一样,无需创建任何类。
并且 groovy 文件通常也是放在 web 目录
下而不是 src 目录
。
简单的 Groovlet
文件名:hello.groovy
Url:http://localhost:8080/hello.groovy
println """<html><head><title>Groovlets 101</title></head><body><p>Welcome to Groovlets 101. As you can seethis Groovlet is fairly simple.</p><p>This course is being run on the following servlet container: </br>${application.getServerInfo()}</p></body></html>"""
Groovlet 隐藏对象
GSP
概念
GSP 框架其实就是一个模板引擎,也可以访问 Groovlet 中的各种隐藏对象
简单的 GSP
<html><head><title>index.gsp</title></head><body><b><% println "hello gsp" %></b><p><% wrd = "Groovy" for (i in wrd){ %> <h1> <%=i%> <br/><%} %></p><form action="groovy/addToy.groovy"> <table> <tr><td>ToyName:</td><td><input type="text" name="toyName"></td></tr> <tr><td>UnitPrice:</td><td><input type="text" name="unitPrice"></td></tr> <tr><td><input type="submit" name="submit"></td></tr> </table></form></body></html>
配置运行环境
IDEA 的配置
Modules Settings
- Modules
web 目录
也设置为 Sources
- Facets
- 确保
Sources Roots
包含web 目录
- 确保
- Artifacts
WEB-INF
下建立lib 目录
,导入相关 Groovy 及其它库
配置Tomcat
Open browser
下的目录为 Tomcat 的根路径Deployment
页可以更改项目路径
0 0
- groovy 速学 - 32 - Web 开发
- groovy 速学 - 03 - 脚本
- groovy 速学 - 07 - 异常
- groovy 速学 - 09 - 集合
- groovy 速学 - 10 - 映射
- groovy 速学 - 11 - 类
- groovy 速学 - 19 - 正则
- groovy 速学 - 22 - IO
- groovy 速学 - 30 - Sql
- groovy 速学 - 01 - 安装与运行
- groovy 速学 - 04 - 操作符
- groovy 速学 - 24 - 与 Java 互调
- groovy 速学 - 31 - Builder 与 Template
- web开发 学什么?
- Web 项目开发方法学
- 轻松学Java Web开发
- 轻松学Java Web开发
- 学JavaScript,做web开发
- 面向对象设计的SOLID原则
- Android ListView控件的使用方法
- 查看代码是否运行在一个我们期望的进程上下文中的方法
- maven ArtifactTransferException: Failure to transfer
- 物联1122班刘佳作业5-6、6-8
- groovy 速学 - 32 - Web 开发
- 用Redis实现分布式锁
- Processes and Threads
- ubuntu创建IdeaIU快捷启动方式
- PHP四大基本排序算法实例
- mysql慢查询日志开启和存储格式
- ios8新特性:pushkit实战总结(voip开发者必读)
- C#委托基础9——Invoke与委托
- jQuery学习笔记1