0

i hav created a jsp page from which i m taking some values and on submit it should pass the parameters to the java class using rest.

< form id="payment" method="post" action="addtogroup">

< ol style="padding: 0;">

< li>< label for="groupId">Group id:< /label>

< input type="text" id="groupId" name="groupId"/>

< br />

< li>< label for="vendorId">Profile Id :< /label>

< input type="text" id="vendorId" name="vendorId"/>
< li> < input type="submit" value="Submit"/> < br /> < /ol>
< /form>

and the java code is:

@RequestMapping(value = "/addtogroup/{groupId}/{vendorId}",method = RequestMethod.POST)

public String addtoGroup(@ModelAttribute("groupId") String groupId,@ModelAttribute("vendorId") String profileId){       
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
     String username = auth.getName();
     System.out.println("group id is="+groupId);
     System.out.println("profileId  is="+profileId);
     System.out.println("username  is="+username);
     grpDao.addToGroup(groupId,profileId,username);

    return "addtogroup";
}

when i type [http://localhost:8080/biznex/rest/addtogroup/2/13] in the address bar directly the code is executed. but when i click submit button in the jsp i get page not found error. plz help me out.

7
  • When you type in address bar request method is GET, so on your server side you need to mention to accept this call using POST Commented Jan 29, 2013 at 5:48
  • and when i change the action="addtogroup/2/13" in the form tag then its executed but the values from the textbox is not taken. is there anything i need to change in the action attribute in the form tag in jsp Commented Jan 29, 2013 at 5:51
  • Got it, your are accepting groupId and vendorId in curly braces from path attributes ((@RequestMapping(value = "/addtogroup/{groupId}/{vendorId}")). You should accept these as Form parameters and not as path attributes if you want 2 and 13 to be accepted from FORM parameters Commented Jan 29, 2013 at 5:55
  • still the same problem page not found. is there anything to change in the action attribute in form tag Commented Jan 29, 2013 at 6:04
  • no while trying form parameters you have changed path in request mapping from "@RequestMapping(value = "/addtogroup/{groupId}/{vendorId}" to "@RequestMapping(value = "/addtogroup" right? can you please paste code with FORM parameters to verify Commented Jan 29, 2013 at 6:09

2 Answers 2

2

< form id="payment" method="post" action="addtogroup"> This statement means submit the FORM data using POST method to the url "currentpath"/"addtogroup"

However, your RESTFUL Server side component expects the url in the form of /addtogoup/{groupid}/{vendorid} in a GET method

I would suggest you to have a JavaScript method which converts your form fields to the URI path- using jQuery or plain JavaScript

Sign up to request clarification or add additional context in comments.

1 Comment

Is JS the only way to achieve it?
0

As thewhiterabbit wrote, you have to pass the complete REST url with the groupid and vendorid.

In order to build it you don't need to use JS, it's enough the spring tag library. Here, how it works:

 <spring:url value="/addtogoup/${form.groupid}/${form.vendorid}" var="actionURL"/>

 <form:form method="POST" action="${actionURL}"  modelAttribute="form">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.