2

I am doing encryption and decryption of message at javascript and want to send result message to the spring controller mvc.

@RequestMapping(value = "/token")
public @ResponseBody String getAllBooks(@RequestParam boolean isAuth, @ModelAttribute("somedata") Token data) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("encryptedToken", data.getValue()); return token;}

Hence the token should hold the value from javascript. I am not using jquery. How to get that value from javascript to Spring mvc controller.

<script>
function Encrypt(msg) {
...................
...................
return encryptedFinally;}
</script>

I want to use this variable (i.e. encryptedFinally) in java controller class.

5
  • Post your Token code and also please make you question more clear Commented Jul 22, 2013 at 10:33
  • Java script has encrypted message the same I wan't to pass from Java script to Controller class method. Commented Jul 22, 2013 at 10:46
  • What about assemble token as a queryString in javascript? Commented Jul 22, 2013 at 14:21
  • How do you send this "/token" request? ajax or submit a form Commented Jul 23, 2013 at 0:47
  • I am sending token using submit a form. Commented Jul 23, 2013 at 4:33

2 Answers 2

1

I think that you have a number of choices:

  1. Add the variable into the Model object (you can follow the @WilQu suggestion for this)
  2. Pass the variable asynchronously with AJAX
  3. pass the variable as a URI parameter like so .../my/path/{var}/something/else/if/it/makes/sense
  4. pass the variable as a query parameter like so /my/path?var=value

At first glance, for your problem I'd choose option number one.

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

Comments

0

Add a hidden input into your form and set the value of this input to the result of the encryption from your javascript code.

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.