• <noscript id="e0iig"><kbd id="e0iig"></kbd></noscript>
  • <td id="e0iig"></td>
  • <option id="e0iig"></option>
  • <noscript id="e0iig"><source id="e0iig"></source></noscript>
  • SpringMVC 的表單標簽庫

    標簽: 表單標簽  springmvc

    1.form標簽


    2.input標簽


    例子:


    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form:form modelAttribute="user" action="register" method="post">
    <table>
    	<tr>
    		<td>名字:</td>
    		<td><form:input path="name"/></td>
    	</tr>
    	<tr>
    		<td>性別:</td>
    		<td><form:input path="sex"/></td>
    	</tr>
    	<tr>
    		<td>年齡:</td>
    		<td><form:input path="age"/></td>
    	</tr>
    
    </table>
    </form:form>

    然后在controller包中的方法中加入:

    model.addAttribute("user",user);

    3.password標簽


    <form:password path="password"/>
    <!-- 上述的springmvc的標簽會被設置成下方的html格式-->
    <input name="password" type="password"/>

    4.hidden標簽


    <form:hidden path="id"/>
    <!-- 上述的springmvc的標簽會被設置成下方的html格式-->
    <input name="id" type="hidden"/>

    5.textarea標簽


    <form:textarea path="book" cols="12" rows="12"/>
    <!-- 上述的springmvc的標簽會被設置成html中的-->
    <textarea rows="12" cols="12" name="book"></textarea>

    6.CheckBox標簽


    列表數據可以包括List,Set和數組。value值在我們綁定中的數據時,CheckBox的狀態為選中。

    <form:checkbox path="coures" label="java" value="java"/>
    <form:checkbox path="coures" label="Golang" value="Golang"/>
    <form:checkbox path="coures" label="CPP" value="CPP"/>

    7.checkboxes標簽



    8.radiobutton標簽


    9.radiobuttons標簽


    一個小栗子:

    web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    	id="WebApp_ID" version="3.1">
    	<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
    	<servlet>
    		<servlet-name>springDispatcherServlet</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>classpath:springmvc.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<!-- Map all requests to the DispatcherServlet for handling -->
    	<servlet-mapping>
    		<servlet-name>springDispatcherServlet</servlet-name>
    		<url-pattern>/</url-pattern>
    	</servlet-mapping>
    	
    
    </web-app>

    放在src目錄下的springmvc.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
    		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    	<context:component-scan base-package="com.majun"></context:component-scan>
    
    	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<property name="prefix" value="/WEB-INF/views/"/>
    	<property name="suffix" value=".jsp"></property>
    
    	</bean>
    </beans>
    
    放在src目錄下的不同包下兩個實體類:
    package com.majun.controller;//控制層的包
    import java.util.ArrayList;
    import java.util.LinkedList;
    import java.util.List;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    import com.majun.entity.*;
    @Controller
    @RequestMapping("spring")
    public class Test {
    	@RequestMapping(value="/testRadiobuttons",method=RequestMethod.GET)
    	public String testRadiobuttons(Model model) {
    		User user=new User();
    		user.setSex("男");
    		List<String> sexList=new ArrayList<String>();
    		sexList.add("男");
    		sexList.add("女");
    		model.addAttribute("user",user);
    		model.addAttribute("sexList",sexList);	
    		return "testRadiobuttons";
    	}
    	
    }
    package com.majun.entity;//實體類
    
    public class User {
    	private String sex;
    
    	public String getSex() {
    		return sex;
    	}
    
    	public void setSex(String sex) {
    		this.sex = sex;
    	}
    	
    }
    

    放在WEB-INF目錄下的views文件夾下(視圖層):

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h2>hello</h2>
    <form:form modelAttribute="user" method="post" action="testRadiobuttons">
    <table>
    	<tr>
    		<td>性別:</td>
    		<td><form:radiobuttons path="sex" items="${sexList }"/>
    		</td>
    	</tr>
    </table>
    </form:form>
    </body>
    </html>


    10.select標簽


    11.option標簽


    12.options標簽




    13.erros標簽

    版權聲明:本文為qq_40587575原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
    本文鏈接:https://blog.csdn.net/qq_40587575/article/details/80157738

    智能推薦

    SpringMVC標簽庫 學習筆記

    SpringMVC 提供了一些標簽庫,可以幫助我們實現 post(增)get(查)delete(刪)put(改)的操作,還可以實現數據綁定。 下面我們介紹一些這些標簽: 第一步:引入標簽庫,在jsp界面寫入如下代碼段 第二步:使用標簽: 前端 其中commandName的默認值是command,如果不設置則,map必須要.put("command",per) 后端 現在我們就可...

    SpringMVC--數據綁定和表單標簽的應用(附帶實例)

    SpringMVC數據綁定和表單標簽的應用 1) 創建工程并導入相關JAR包 應用中需要使用 JSTL,因此不僅需要將 Spring MVC 的相關 JAR 包復制到應用的 WEN-INF/lib 目錄下,還需要從 Tomcat 的 webapps\examples\WEB-INF\lib 目錄下將 JSTL 的相關 JAR 包復制到應用的 WEN-INF/lib 目錄下。 2)配置web.xml...

    JavaWeb-20-SpringMVC的表單標簽以及引入靜態資源

    目錄 1:頁面操作 2:用了表單標簽的頁面可能會報這個錯誤;請求域中沒有一個command類型的對象;來到頁面之前一定要給請求域中放這個對象; ? 3:后端操作 4:springmvc引入靜態資源 1:當在頁面使用靜態資源時回報異常 2:原因是因為springmvc在web.xml中設置了攔截除jsp外所有的請求 3:解決辦法:配置 4:關于作用 通過 SpringMVC的表單...

    springmvc筆記-4-標簽庫

    1.form 2.input 3.password 4.hidden 5.textarea 6.checkbox和checkboxes 7.radiobutton和radiobuttons 8.select 9.option和options 10.errors springmvc的表單標簽庫實現類在spring-webmvc.jar,標簽庫的描述文件在spring-form.tld 要是用spri...

    SpringMVC表單回顯

    做課程設計的時候遇到一個問題弄了好久,找了好久也沒有找到解決辦法,弄了好久終于弄出來了,人生的第一篇博客來補充一下吧, 先說Eclipse拋出的異常: 嚴重: Invalid property ‘rigth’ of bean class [com.learn.train.entitis.User]: Bean property ‘rigth’ is ...

    猜你喜歡

    SpringMVC 表單注冊頁

    學習參考自易百教程 1、程序目錄如下 2、controller: 3、User 4、web.xml 5、spring-servlet.xml 6、register.jsp 7、show.jsp 結果...

    SpringMVC Form表單

    學習參考自易百教程 1、新建javaWeb工程springMVC_Form,選擇Web服務器 2、點擊next,取消生成index.jsp,勾選web.xml,取消導入jstl庫 3、點擊finish完成,右鍵項目,部署spring開發 取消勾選該頁所有選擇 4、點擊finish完成。接下來編寫student類和controller控制器添加dispatcher-servlet.xml,完成web...

    HTML中常用操作關于:頁面跳轉,空格

    1.頁面跳轉 2.空格的代替符...

    freemarker + ItextRender 根據模板生成PDF文件

    1. 制作模板 2. 獲取模板,并將所獲取的數據加載生成html文件 2. 生成PDF文件 其中由兩個地方需要注意,都是關于獲取文件路徑的問題,由于項目部署的時候是打包成jar包形式,所以在開發過程中時直接安照傳統的獲取方法沒有一點文件,但是當打包后部署,總是出錯。于是參考網上文章,先將文件讀出來到項目的臨時目錄下,然后再按正常方式加載該臨時文件; 還有一個問題至今沒有解決,就是關于生成PDF文件...

    電腦空間不夠了?教你一個小秒招快速清理 Docker 占用的磁盤空間!

    Docker 很占用空間,每當我們運行容器、拉取鏡像、部署應用、構建自己的鏡像時,我們的磁盤空間會被大量占用。 如果你也被這個問題所困擾,咱們就一起看一下 Docker 是如何使用磁盤空間的,以及如何回收。 docker 占用的空間可以通過下面的命令查看: TYPE 列出了docker 使用磁盤的 4 種類型: Images:所有鏡像占用的空間,包括拉取下來的鏡像,和本地構建的。 Con...

    精品国产乱码久久久久久蜜桃不卡