【发布时间】:2023-03-10 17:40:01
【问题描述】:
我希望能够看到用户在下一页的下拉列表中选择的选项的值。 我正在努力实现这一目标。 因此,用户有一个下拉列表,可以在其中选择去往的国家/地区列表,单击的国家/地区将显示在其他页面上 我该怎么做,有人可以指导我吗
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<form action ="some.jsp" class="form">
<form:form method = "POST" action=/Country/ model attribute = "model">
</div>
<a id="ToProductsBtn" href="/Country/" class="btn btn-default">lets go</a>
</form:form>
<title>choose a country</title>
</head>
<body>
<h1>choose your next destination</h1>
<select>
<option value="" disabled="disabled" selected="selected">Please select a country</option>
<option value="England">England</option>
<option value="Scotland">Scotland</option>
<option value ="ireland">Ireland</option>
<option value="northern Ireland">Northern Ireland</option>
<option value="spain">Spain</option>
<input type="submit" href="/Country/">
<a id="ToProductsBtn" href="/Country/" class="btn btn-default">lets go</a>
</select>
<!DOCTYPE html>
<html>
<head>
</body>
</html>
</select>
</form>
</body>
</html>
然后他们选择的国家/地区应该显示在此页面上:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome</title>
</head>
<h1></h1>
<h2> ${name}</h2>
<body>
</body>
</html>
我的控制器类:
package travel.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.view.RedirectView;
import travel.domain.Order;
@Controller
public class Place {
@RequestMapping(value="/addcountry")
public String place(@RequestParam(value="name", required=false, defaultValue="PLACE") String name, Model model) {
model.addAttribute("name", name);
return "form/Place";}
@RequestMapping (value="/Country")
public String Country(@RequestParam(value="Mycountry", required=false, defaultValue="myCountry") String name, Model model) {
model.addAttribute("name", name);
return "form/Country";}
}
【问题讨论】:
标签: java html spring-mvc jsp model-view-controller