Remo
Remo

Reputation: 145

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists error

Web.xml

Books Management

<servlet>
    <servlet-name>BooksManagement</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
    <servlet-name>BooksManagement</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>/student.jsp</welcome-file>
</welcome-file-list>

My controller is AddStudentController

@Controller
public class AddStudentController {

    @RequestMapping(value = "/student", method = RequestMethod.GET)
    public ModelAndView student() {
    return new ModelAndView("student", "command", new Students());
    }

    @RequestMapping(value = "/addStudent", method = RequestMethod.POST)
    public String addStudent(@ModelAttribute("SpringWeb") Students student,ModelMap model) {
    model.addAttribute("firstName", student.getFirstName());
    model.addAttribute("lastName", student.getLastName());
    model.addAttribute("id", student.getId());

    return "result";
    }
}

Folder Structure

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists error

Upvotes: 0

Views: 2451

Answers (1)

Remo
Remo

Reputation: 145

At first, I was trying to hit student.jsp without hitting in index.jsp. After I give <a href="student">Click here...</a> in index.jsp.

Also, added

<welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list>

in web.xml

Now it's solved

As Controller was searching /student it was nowhere mentioned

@Controller
public class AddStudentController {
    @RequestMapping(value = "/student", method = RequestMethod.GET)
    public ModelAndView student() {
    return new ModelAndView("student", "command", new Students());
    }

Upvotes: 1

Related Questions