groovy 速学 - 32 - Web 开发
发布时间:2020-12-14 16:47:47 所属栏目:大数据 来源:网络整理
导读:目录 Web开发 Web上下文 Groovlet 概念 简单的 Groovlet Groovlet 隐藏对象 GSP 概念 简单的 GSP 配置运行环境 IDEA 的配置 摘要 groovlet,gsp Web开发 Web上下文 要使用 Groovy 开发 Web 程序,首先需要配置上下文,更新 web.xml 文件。 servlet servlet-n
目录
摘要
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>
上述配置定义了以 Groovlet概念Groovlet 以 Servlet 为基础,但是无需继承 HttpServlet,也无需实现 doGet(),doPost() 方法。 简单的 Groovlet文件名:hello.groovy println """ <html><head> <title>Groovlets 101</title> </head> <body> <p> Welcome to Groovlets 101. As you can see this 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
配置Tomcat
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |