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

 JSP & JSTL

View resolvers

InternalResourceViewResolver and the ResourceBundleViewResolver常用来解析视图,在web应用上下文里定义

<!-- the ResourceBundleViewResolver -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">

<property name="basename" value="views"/>

</bean>

# And a sample properties file is uses (views.properties in WEB-INF/classes):

welcome.(class)=org.springframework.web.servlet.view.JstlView

welcome.url=/WEB-INF/jsp/welcome.jsp

productList.(class)=org.springframework.web.servlet.view.JstlView

productList.url=/WEB-INF/jsp/productlist.jsp

ResourceBundleViewResolver需要properties文件定义view名字映射的class,url; ResourceBundleViewResolver可以使用不同类型视图只用同一个Resovler

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

<property name="prefix" value="/WEB-INF/jsp/"/>

<property name="suffix" value=".jsp"/>

</bean>

InternalResourceBundleViewResolver可以用来解析jsps,最好是使用带目录的/WEB-INF/jsp/指定,避免直接访问

Plain-old JSPs versus JSTL

TLD在常用的jar中用来获取绑定的数据

Using Spring’s form tag library

和其他的form和input标签不同,spring form tag是spring web mvc 完整提供的,访问命令对象和控制器处理的数据,使得jsps更方便

Configuration

The form tag library comes bundled in spring-webmvc.jar. The library descriptor is called spring-form.tld.

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

The form tag

<form:form>

<table>

<tr>

<td>First Name:</td>

<td><form:input path="firstName" /></td>

</tr>

<tr>

<td>Last Name:</td>

<td><form:input path="lastName" /></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value="Save Changes" />

</td>

</tr>

</table>

</form:form>

firstName和lastName的值是由PageContext中的命令对象提供的

<form method="POST">

<table>

<tr>

<td>First Name:</td>

<td><input name="firstName" type="text" value="Harry"/></td>

</tr>

<tr>

<td>Last Name:</td>

<td><input name="lastName" type="text" value="Potter"/></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value="Save Changes" />

</td>

</tr>

</table>

</form>

其中form的变量名是返回对象的命令,如果要将form返回对象放入model在另一个名字下,你可以如下绑定名字

<form:form commandName="user">

<table>

<tr>

<td>First Name:</td>

<td><form:input path="firstName" /></td>

</tr>

<tr>

<td>Last Name:</td>

<td><form:input path="lastName" /></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value="Save Changes" />

</td>

</tr>

</table>

</form:form>

The input tag

The checkbox tag

将input tag 的 type =checkbox

Eg:user preferences类

public class Preferences {

private boolean receiveNewsletter;

private String[] interests;

private String favouriteWord;

public boolean isReceiveNewsletter() {

return receiveNewsletter;

}

public void setReceiveNewsletter(boolean receiveNewsletter) {

this.receiveNewsletter = receiveNewsletter;

}

public String[] getInterests() {

return interests;

}

public void setInterests(String[] interests) {

this.interests = interests;

}

public String getFavouriteWord() {

return favouriteWord;

}

public void setFavouriteWord(String favouriteWord) {

this.favouriteWord = favouriteWord;

}

}

Form.jsp  like:

<form:form>

<table>

<tr>

<td>Subscribe to newsletter?:</td>

<%-- Approach 1: Property is of type java.lang.Boolean --%>

<td><form:checkbox path="preferences.receiveNewsletter"/></td>

</tr>

<tr>

<td>Interests:</td>

<%-- Approach 2: Property is of an array or of type java.util.Collection --%>

<td>

Quidditch: <form:checkbox path="preferences.interests" value="Quidditch"/>

Herbology: <form:checkbox path="preferences.interests" value="Herbology"/>

Defence Against the Dark Arts: <form:checkbox path="preferences.interests" value="Defence Against the Dark Arts"/>

</td>

</tr>

<tr>

<td>Favourite Word:</td>

<%-- Approach 3: Property is of type java.lang.Object --%>

<td>

Magic: <form:checkbox path="preferences.favouriteWord" value="Magic"/>

</td>

</tr>

</table>

</form:form>

There are 3 approaches to the checkbox tag which should meet all your checkbox needs.

· Approach One - When the bound value is of type java.lang.Boolean, the input(checkbox) is marked as checked if the bound value is true. The value attribute corresponds to the resolved value of the setValue(Object) value property.

· Approach Two - When the bound value is of type array or java.util.Collection, the input(checkbox) is marked as checked if the configured setValue(Object) value is present in the bound Collection.

· Approach Three - For any other bound value type, the input(checkbox) is marked as checked if the configured setValue(Object) is equal to the bound value.

· <tr>

·     <td>Interests:</td>

·     <td>

·         Quidditch: <input name="preferences.interests" type="checkbox" value="Quidditch"/>

·         <input type="hidden" value="1" name="_preferences.interests"/>

·         Herbology: <input name="preferences.interests" type="checkbox" value="Herbology"/>

·         <input type="hidden" value="1" name="_preferences.interests"/>

·         Defence Against the Dark Arts: <input name="preferences.interests" type="checkbox" value="Defence Against the Dark Arts"/>

·         <input type="hidden" value="1" name="_preferences.interests"/>

·     </td>

· </tr>

· What you might not expect to see is the additional hidden field after each checkbox. When a checkbox in an HTML page is not checked, its value will not be sent to the server as part of the HTTP request parameters once the form is submitted, so we need a workaround for this quirk in HTML in order for Spring form data binding to work. The checkbox tag follows the existing Spring convention of including a hidden parameter prefixed by an underscore ("_") for each checkbox. By doing this, you are effectively telling Spring that "the checkbox was visible in the form and I want my object to which the form data will be bound to reflect the state of the checkbox no matter what".

The checkboxes tag

不会全显示,只有在运行时返回值在集合中array,list,map

<form:form>

<table>

<tr>

<td>Interests:</td>

<td>

<%-- Property is of an array or of type java.util.Collection --%>

<form:checkboxes path="preferences.interests" items="${interestList}"/>

</td>

</tr>

</table>

</form:form>

The radiobutton tag

<tr>

<td>Sex:</td>

<td>

Male: <form:radiobutton path="sex" value="M"/> <br/>

Female: <form:radiobutton path="sex" value="F"/>

</td>

</tr>

The radiobuttons tag

运行时显示,In the case where you use a Map, the map entry key will be used as the value and the map entry’s value will be used as the label to be displayed.

<tr>

<td>Sex:</td>

<td><form:radiobuttons path="sex" items="${sexOptions}"/></td>

</tr>

The select tag

The option tag

The options tag

The textarea tag

The hidden tag

The errors tag

public class UserValidator implements Validator {

public boolean supports(Class candidate) {

return User.class.isAssignableFrom(candidate);

}

public void validate(Object obj, Errors errors) {

ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "required", "Field is required.");

ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "required", "Field is required.");

}

}

The form.jsp would look like:

<form:form>

<table>

<tr>

<td>First Name:</td>

<td><form:input path="firstName" /></td>

<%-- Show errors for firstName field --%>

<td><form:errors path="firstName" /></td>

</tr>

<tr>

<td>Last Name:</td>

<td><form:input path="lastName" /></td>

<%-- Show errors for lastName field --%>

<td><form:errors path="lastName" /></td>

</tr>

<tr>

<td colspan="3">

<input type="submit" value="Save Changes" />

</td>

</tr>

</table>

</form:form>

· path="*" - displays all errors

· path="lastName" - displays all errors associated with the lastName field

· if path is omitted - object errors only are displayed

显示一系列错误在网页的上面,显示具体的错误在field旁边

<form:form>

<form:errors path="*" cssClass="errorBox" />

<table>

<tr>

<td>First Name:</td>

<td><form:input path="firstName" /></td>

<td><form:errors path="firstName" /></td>

</tr>

<tr>

<td>Last Name:</td>

<td><form:input path="lastName" /></td>

<td><form:errors path="lastName" /></td>

</tr>

<tr>

<td colspan="3">

<input type="submit" value="Save Changes" />

</td>

</tr>

</table>

</form:form>

HTTP Method Conversion http方法转变

Rest的重要原则是使用统一接口,意味着所有的资源都能被这四种方法操作(get,put,post,delete),对于每一个方法,http规格定义了明确的语义,例如,get必须是安全的操作,没有其他影响,,PUT和delete行为是idempotent,你可以一次又一次重复这些操作,但最终结果是一样的,http定义这四种方式时,html只支持两种,get和post.幸运的是有两种变通方案:你可以用javascript使用put和delete,后者简单使用post方法作为参数(在html form中作为隐藏区),之后这是Spring’s HiddenHttpMethodFilter做的,是基本的servlet过滤器,可以和任何web framework工作,简单将filter加入web.xml,隐藏参数的方法将被转换为相关的http方法请求

<form:form method="delete">

<p><input type="submit" value="Delete Pet"/></p>

</form:form>

是一个http post,实际是一个delete方法隐藏在一个请求参数中,将会被HiddenHttpMethodFilter:

<filter>

<filter-name>httpMethodFilter</filter-name>

<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>httpMethodFilter</filter-name>

<servlet-name>petclinic</servlet-name>

</filter-mapping>

相应的@C otroller方法如下

@RequestMapping(method = RequestMethod.DELETE)

public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {

this.clinic.deletePet(petId);

return "redirect:/owners/" + ownerId;

}

HTML5 Tags

Velocity & FreeMarker

ur web application will need to include velocity-1.x.x.jar or freemarker-2.x.jar

转载于:https://my.oschina.net/iioschina/blog/670601

view技术简单了解相关推荐

  1. 单臂路由与三层交换技术简单介绍

    单臂路由与三层交换技术简单介绍 单臂路由与三层交换技术 一.单臂路由技术 二.使用实例 二.三层交换技术 使用实例 总结 单臂路由与三层交换技术 我们如何实现不同vlan之间的通信: 单臂路由技术:二 ...

  2. Linux 下UVCamp;V4L2技术简单介绍(二)

    通过前文Linux 下UVC&V4L2技术简单介绍(一)我们了解了UVC和V4L2的简单知识. 这里是USB设备的文档描写叙述:http://www.usb.org/developers/do ...

  3. TTS技术简单介绍和Ekho(余音)TTS的安装与编程

    TTS技术简单介绍和Ekho(余音)TTS的安装与编程 zouxy09@qq.com http://blog.csdn.net/zouxy09 一.TTS技术简单介绍: TTS技术,TTS是Text ...

  4. (一) Qt Model/View 的简单说明

    目录: (一) Qt Model/View 的简单说明 .预定义模型 (二)使用预定义模型 QstringListModel例子 (三)使用预定义模型QDirModel的例子 (四)Qt实现自定义模型 ...

  5. Oracle数据库:创建和删除视图view,简单和复杂视图,内建视图,topN分析,oracle分页查询

    Oracle数据库:创建和删除视图view,简单和复杂视图,内建视图,topN分析,oracle分页查询 2022找工作是学历.能力和运气的超强结合体,遇到寒冬,大厂不招人,可能很多算法学生都得去找开 ...

  6. ekho tts 下载_TTS技术简单介绍和Ekho(余音)TTS的安装与编程

    TTS技术简单介绍和Ekho(余音)TTS的安装与编程zouxy09@qq.comhttp://blog.csdn.net/zouxy09 一.TTS技术简单介绍:TTS技术,TTS是Text To ...

  7. 通信对抗干扰技术简单综述与MATLAB仿真

    由于公式太多,一个一个敲过来实在费时.请点击下面链接阅读原文,造成不便十分抱歉 通信对抗干扰技术简单综述与MATLAB仿真 - 子木的文章 - 知乎 https://zhuanlan.zhihu.co ...

  8. ekho tts 下载_TTS技术简单介绍和Ekho(余音)TTS的安装与编程 | 学步园

    一.TTS技术简单介绍: TTS技术,TTS是Text To Speech的缩写,即"从文本到语音".它将计算机自己产生的.或外部输入的文字信息转变为可以听得懂的.流利的汉语口语( ...

  9. bigpipe php,php 使用 bigpipe技术 简单笔记

    php 使用 bigpipe技术 简单笔记 php 使用 bigpipe技术 简单笔记 1.配置nginx 关闭proxy_buffering 为 off ,关闭 gzip压缩,  设置 fastcg ...

最新文章

  1. mysql如何进行压测_详解MySQL如何按表创建千万级的压测数据
  2. 连接池 druid(阿里巴巴的框架)
  3. 我的WCF之旅(13):创建基于MSMQ的Responsive Service
  4. 检查div是否存在jquery [重复]
  5. mac电脑的磁盘空间变得越来越小
  6. 去重 list_List 去除重复数据的 5 种正确姿势!
  7. cad2008加载 et拓展工具_CAD设计师的工具,55款实用插件,收藏起来
  8. php金字塔怎么理解,我理解的金字塔原理
  9. 扫描仪 无线 打印服务器,自带扫描仪、还能无线打印,Find X2 Pro实用功能分享...
  10. Python批量合并多个excel文件
  11. ElementUI ===> 表单 rules 规则
  12. Java IO基础知识
  13. 靠一套PPT上市估值120亿:新能源韭菜的自我修养
  14. Python爬虫(一)——58同城租房信息
  15. Threejs入门教程
  16. Illustrator 脚本初识
  17. 一个开发周期为6个月的中小型软件开发项目成本预算大致表
  18. 系统集成项目管理工程师复习方法:思维导图辅助记忆
  19. 2023年北京化工大学动力工程考研经验
  20. 米家小相机最新固件_#本站首晒#699元的运动相机 — 小米 米家小相机开箱简评...

热门文章

  1. input type=text 无法使用.html(),input type=”text” (Elements) – HTML 中文开发手册
  2. linux怎么进入字符命令界面,如何进入CentOS字符界面及窗口模式
  3. Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理
  4. svn 分支合并(Subclipse例子)
  5. Oracle中NUMBER类型如果不指定长度和小数点精度默认是多长
  6. 游戏201712-2
  7. Django之ORM操作
  8. javascript立体学习指南
  9. VS code配置docker的shell环境
  10. Android的BUG(四) - Android app的卡死问题