When I am putting the jsp files outside the views folder under webapp it works well
but When I cut and paste them inside views folder first jsp page (practice1.jsp displays but when I click the submit button following errors comes:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed May 19 17:52:21 IST 2021
There was an unexpected error (type=Not Found, status=404).
What I have tried:
/practice2/src/main/java/com/example/demo/Practice1Application.java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.*")
public class Practice1Application {
public static void main(String[] args) {
SpringApplication.run(Practice1Application.class, args);
System.out.println("Application started");
}
}
/practice2/src/main/java/com/example/demo/Practice1Controller.java
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class Practice1Controller {
@RequestMapping("/")
public String practice()
{
return "practice1Jsp.jsp";
}
@RequestMapping("/add")
public ModelAndView add(@RequestParam("num1")int n1,@RequestParam("num2")int n2)
{
ModelAndView mv=new ModelAndView();
mv.setViewName("result.jsp");
int num3=n1+n2;
mv.addObject("num3",num3);
return mv;
}
}
/practice2/src/main/resources/application.properties
spring.mvc.view.prefix= /views/
/practice2/src/main/webapp/views/practice1Jsp.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>'
<title>Insert title here
hiiiiii
Hello <br>
<br><br>
<br>
/practice2/src/main/webapp/views/result.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" isELIgnored="false"%>
<title>Insert title here
REQUEST RECEIVED
Result is :${num3}