SpringMVC入門小例子——表單提交
主要檔案清單
- WebContent/WEB-INF/web.xml
- src/springmvc-servlet.xml
- src/test.SpringMVC/MVCController.java
- WebContent/index.jsp
- WebContent/jsp/hello.jsp
- 專案結構圖
1、web.xml
- 在預設的內容基礎之上配置一個servlet,即DispatcherServlet
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc-servlet.xml</param-value>
</servlet>
<servlet-mapping>
<servlet-name> springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
- 注:配置檔案springmvc-servlet.xml的檔名是在
<servlet-name>
標籤值的基礎之上加上-servlet組成
2、springmvc-servlet.xml
- 配置註解:
<context:component-scan base-package="test.SpringMVC"/>
<mvc:annotation-driven />
- 配置檢視解析器ViewResolver
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
- 配置handler
<mvc:default-servlet-handler />
3、MVCController.java
- 主要內容
@Controller
// @RequestMapping("/mvc")
public class MVCController {
//http://localhost:8080/SpringMVCTest/hello
@RequestMapping("/hello")
public String hello(HttpServletRequest req, Model model) {
String userName = req.getParameter("userName");
model.addAttribute("userName", "hello :" + userName);
return "hello";//通過檢視解析器返回給hello.jsp
//下面這個也可以用,但用的時候需要取消掉上述檢視解析器中的字首配置
//return "/jsp/hello";
}
}
- 注:方法隨便寫,返回值必須為String,引數可有可無,還可以傳入一些其他的引數,但具體有哪些請自行查閱。這個返回值就是檢視路徑,配合檢視解析器使用。
4、index.jsp
- 沒什麼東西,就一個form表單
<form action="hello" method="post>
userName:<input type="text" name="userName" />
<input type="submit" value="submit" />
</form>
5、hello.jsp
- 沒什麼東西,就一個
<h1>${userName }</h1>
,用於顯示上述form表單傳的username
值。
6、執行結果
index.jsp
hello.jsp
相關推薦
SpringMVC入門小例子——表單提交
主要檔案清單 WebContent/WEB-INF/web.xml src/springmvc-servlet.xml src/test.SpringMVC/MVCController.java W
SpringMVC學習筆記:表單提交 參數的接收
服務器 book postman pan json格式數據 ica 上傳圖片 異步 collect SpringMVC可以接收原生form表單和json格式數據 有一個名為Book的model,其中的屬性如下: 字符串類型的name,數字類型的price,數組類型的c
微信小程式表單提交
點選按鈕提交表單查詢,查詢成功後顯示資訊補充按鈕,點選資訊補充按鈕跳轉到資訊補充頁面 1、wxml <view class='mian'> <form bindsubmit='submitForm'> <view class='item'
微信小程序 PHP後端form表單提交實例詳解
toolbar 什麽 例子 control .info class odi 根據 綁定 微信小程序php後端form表單 https://www.cnblogs.com/tdalcn/p/7092716.html 1.小程序相對於之前的WEB+PHP建站來說,個人理解為只是
小程式 <web-view></web-view> 中使用 form 表單提交
在最近的小程式專案中,使用到了 <web-view></web-view> 內嵌 H5 頁面,在 H5 中需要使用 form 表單提交資料。 H5 使用的技術框架是 vue+vuex,剛開始編碼如下: //form表單,v-model繫結資料 <form :action
微信小程式form表單提交到資料庫
1.小程式目錄圖 js檔案是邏輯控制,主要是它傳送請求和接收資料, json 用於此頁面區域性 配置並且覆蓋全域性app.json配置, wxss用於頁面的樣式設定, wxml就是頁面,相當於html
easyUI入門《二十九、form案例:表單提交以及驗證重置清空》
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <!--引入
SpringMVC form表單提交list物件集合
form表單頁面 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&
測試springmvc表單提交新增資料,伺服器報400錯誤-----HTTP Status 400
用postman測試一個新增資料的控制器方法時,報了400錯誤 經查,是請求無效的意思 一般可能出現在有Date格式的資料表中 我的模型類有個Date型別的資料,如果要正常傳入,可以新增以下程式碼在Date格式資料上方,如圖所示 @DateTimeFormat(patter
Servlet的5種方式實現表單提交(註冊小功能),後臺獲取表單資料
用servlet實現一個註冊的小功能 ,後臺獲取資料。 註冊頁面: 註冊頁面程式碼 : <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title&g
微信小程式學習筆記(三)表單提交、PHP後臺資料互動
【form表單提交】 form.wxml: <form bindsubmit="formSubmit" bindreset="formReset"> <view> 暱稱:<input type="text" name="nic
【已解決】SpringMVC表單提交結果頁面出現400錯誤的可能原因分析
頁面錯誤: The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed reques
springMVC資料傳遞案例------利用form表單提交資料
這一章簡單的例舉一下form表單是怎麼講資料傳遞到後臺,又是怎麼接收,再傳回來 執行用的框架是之前搭建的,已經匯出來了,有興趣的可以直接去下載 ssm框架 在這個框架的基礎上加入了幾個jsp頁
微信小程式中form 表單提交和取值例項詳解
我們知道,如果我們直接給 input 新增 bindinput,比如:<input bindinput="onUsernameInput" />,那麼可以在 onUsernameInput 中直接使用 e.detail.value,即: onUsernameInput : function(e)
微信小程式(十九)——表單資料提交和小程式表單賦值(組裝資料)
前端表單程式碼.wxml: <form > <view class='form-box'> <view class='form-item'>
springmvc使用實體類接收表單提交資料中含有String型別對應Date型別的不匹配報錯400時如何處理
springmvc使用實體類接收表單提交資料中含有String型別對應Date型別的不匹配情況,頁面提交表單報錯400,時如何處理? 參看部落格:http://blog.csdn.net/u014079773/article/details/51865178 我
微信小程式weui線上入門教程-WeUi表單元件-slider滑塊
效果圖 wxml程式碼 <view class="page"> <view class="page__hd"> <view class="page__title">Slider</view>
微信小程式weui線上入門教程-WeUi表單元件-uploader上傳
效果圖 wxml程式碼 <view class="page"> <view class="page__hd"> <view class="page__title">Uploader</view>
微信小程式weui線上入門教程-WeUi表單元件-input輸入框
效果圖 wxml程式碼 <view class="page" xmlns:wx="http://www.w3.org/1999/xhtml"> <view class="page__hd"> <view class="p
微信小程式weui線上入門教程-WeUi表單元件-list列表
效果圖 wxml程式碼 <view class="page"> <view class="page__hd"> <view class="page__title">List</view>