MDP
MDP

Reputation: 4267

How to handle URL and @RequestMapping in Spring MVC

I have a doubt about the best way to handle the @RequestMapping.

For example:

with this url http://localhost:8080/SpringExample/admin/personaListForm/1 I reach a form, controlled by this @RequestMapping:@RequestMapping("/admin/personaListForm/{tipoPersona}")
As you can see "1" is a variable.

This is my form:<form:form action="personaListFormSent">

As you can see, If I submit the form, I'll be sent to this url http://localhost:8080/SpringExample/admin/personaListForm/personaListFormSent (because of the "/1"). The problem is that i don't want to go there, I want to go to http://localhost:8080/SpringExample/admin/personaListFormSent

I may solve the problem editing the form this way <form:form action="../personaListFormSent"> but it doesn't seem a professional way to handle this problem, since if tomorrow I need to add more variable I'll have to add more "../" to the form tag.

thank you

Upvotes: 0

Views: 287

Answers (2)

soung
soung

Reputation: 1614

You can use ${pageContext.request.contextPath}/personaListFormSent.

<form:form action="${pageContext.request.contextPath}/personaListFormSent">

So you will go to http://localhost:8080/SpringExample/personaListFormSent when you post the form.

Upvotes: 1

Send them to action="/personaListFormSent". '/' is the root of your app, so it doesn't matter which is your context path.

Regards,

Jorge

Upvotes: 0

Related Questions