Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
Java
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;
Java
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("/practice1Jsp")
	@RequestMapping("/")
	public String practice()
	{
		//System.out.println("practice1 controller");
		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/

HTML
/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}
Posted
Updated 19-May-21 2:58am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900