0

Before ask this question, I have already read the forum and tried a lot of from forum suggestions. I do not know , maybe i do not clearly understand or maybe the reason that i apply to my current project, however answer on the forum is not working in my project

  • Java:

     @RequestMapping(value = "/warehouseWhisky", method = {RequestMethod.GET, RequestMethod.POST})
     public ModelAndView viewAllWhiskyInWarehouse() {
    
    Iterable<WhiskyDTO> list = whiskyService.seeAllWhisky();
    String  email = receiveEmailFromSecurity.getEmail();
    System.out.println(email);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("viewAvailableWhisky", list);
    modelAndView.addObject("email", email);
    
    modelAndView.setViewName("whisky");
    return modelAndView;
    }
    

    This code correct, I recive in HTML string:

     <input type="button" id="someThingNew" th:value="${email}"/>
    

    enter image description here But I didn't recieve this parameters in js:

      var nameUser = $("#someThingNew").val();
         console.log(nameUser);
    
2
  • What are you calling? It can find the mappings - but the issue in the 2nd variant is you are missing email from the URL. Focus on the first method - what is the URL. Provide some log for this url Commented Aug 15, 2016 at 12:18
  • I send email from java, from DB Commented Aug 15, 2016 at 12:27

2 Answers 2

2

I think the problem is caused because of the special characters in email like '@'. In other word you cannot send email address using @PathVariable (with ordinary routing configuration). Instead of @PathVariable, you can send email using @RequestParam and send it as a query parameter.

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

3 Comments

can you show example, I know how send from js to java, from HTML to java use '@RequestParam', but I don't understand how send from java to JS use '@RequestParam'
Why do you want to send from Java to JS. Keep one thing in mind that your client side JS script can not handle the requests, so you can not send as a request param but you can send in response If you want.
I can't understand the meaning of "send from Java to JS", anyway you can send email address to your controller as a query parameter using @RequestParam. After that you have the email address in the scope of method and you can do anything you want.
0

I think the first method is probably fine - just you are calling the wrong URL. What is your server mapping? I would expect something like -

http://localhost:8080/warname/warehouseWhisky/[email protected]

The issue with the second one is that its expecting similar to the following - which is why you are getting a 500

@RequestMapping(value = "/warehouseWhisky/{email}")

4 Comments

No - your server will say something like localhost:8080/<myapp>/
try localhost:8080/warehouseWhisky/warehouseWhisky/[email protected]
I do shoppingCart and when User click on button "Buy", I want to send his email to JS from java, and send him, on the his email, the order from shoppingCart. I don't know what email will be
No its a test of the url - it should not return 404. In fact replace the method body with a sys out. Incidentally why do you take email as a param then overwrite?

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.