Madhusudan
Madhusudan

Reputation: 4815

getting wrong/invalid navigation in spring-mvc web application

I am trying a simple web application to implement CRUD operations. When I run my application on tomcat-7 then i get my home page. When I click on 'add Spcr' link then it shows addSpcr.jsp form page. After filling form when I click on save then its giving me following error:

HTTP Status 404 - /insert
description:requested resource is not available

addSpcr.jsp page:

 <form method="POST" action="/insert" >
 //form body
 </form>

When I hit on save button then ideally it should navigate to

https://localhost:8080/SampleLeaderTool/insert

but its navigating to url

https://localhost:8080/insert

Method from controller is:

@RequestMapping(value = "/insert",method = RequestMethod.POST) 
public ModelAndView insertData(@ModelAttribute Spcr spcr){
    if (spcr != null)  
           a.insertData(spcr); 

    ModelAndView model = new ModelAndView("success");
    return model;
}

view resolver from spring-servlet.xml:

<bean id="viewResolver"  
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  <property name="prefix" value="/WEB-INF/jsp/" />  
  <property name="suffix" value=".jsp" />  
</bean>

I am not able to figure out what I did wrong here.

Upvotes: 0

Views: 120

Answers (3)

sanjay
sanjay

Reputation: 437

you can write this code.hope this is work.

<form method="POST" action="${pageContext.request.contextPath}/insert" >
 //form body
 </form>

Upvotes: 0

pguetschow
pguetschow

Reputation: 5337

You have to include ${pageContext.servletContext.contextPath} before doing an insertion, becaus it's missing the path for the context of the action

Upvotes: 0

Paulius Matulionis
Paulius Matulionis

Reputation: 23415

That is because you are missing a context path in your form action.

To avoid this kind of issues include: ${pageContext.servletContext.contextPath} before /insert.

For e.g.:

 <form method="POST" action="${pageContext.servletContext.contextPath}/insert" >
 //form body
 </form>

Upvotes: 1

Related Questions