Spring Home Page
On page Form we should have
Form text
textfield
submit button
———————————————
When we enter a name in textfield and we press submit button we should be redirected to another page
———————————————
Your name is + textfield content
———————————————
//HomeController
@Controller
public class HomeController {
@RequestMapping("/")
public String getHome() {
return "home-page";
}}
//FormController
@Controller
public class FormController {@RequestMapping("/form-data")
public String receiveData() {
return "form-data";
}
@RequestMapping("/process-data")
public String processData() {
return "process-data";
}}
//home-page.jsp
<h1>Home Page</h1>
<a href="form-data">Go to form</a>//form-data.jsp
<h1>Form</h1>
//process-data.jsp
<h1>Your name is: </h1>
${param.studentName}For previous application add another method in FormController that will get student parameter name, will make it uppercase and add it on the process-from page
Output should be like this:
Process form
Student name is: Radu
Student Uppercase name is: Yo!RADU
//FormController method
@RequestMapping("/process-formV2")
public String getProcessFormV2(HttpServletRequest request, Model model) {
String name = request.getParameter("student"); name = "Yo!" + name.toUpperCase();
model.addAttribute("message", name);
return "process-form";
}//process-form
<h1>Process form</h1>
Student name is: ${param.student}
<br>
Student Uppercase name is: ${message}On process-form page add an image from resources/images folder
img witdh=”300” height=”300” src=”${pageContext.request.contextPath}/resources/images/box.jpg”