M
M
Mikhail Voitenko2014-07-01 18:17:14
JavaScript
Mikhail Voitenko, 2014-07-01 18:17:14

How to return an object of type java.util.Date from JavaScript?

The Javascript calls a Java method that accepts a java.util.Date. On the Java side, the code cannot be changed in any way. How can you generate a Java date object (even if it's empty) using Javascript?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AlexanderSImex, 2014-07-03
@AlexanderSImex

Let's say you entered a date in <,input> on a "js" page:
<,input id="date" class="form-control" type="text">
further:
<,script type="text/javascript">
____vardate = $("#date").val();
____var formatDate = new Date(date);
<,/script>
After that you can pass formatDate (e.g. ajax) to java in "controller" and java will take it as a date:
//Spring using
@RequestMapping(method = RequestMethod.POST, value = "/your URL" )
@ResponseBody
public List methodName(
@RequestParam(value = "formatDate"
return contractList;
}
...but it will work in the case that Skeeeve is talking about
PS anyd3v hello from Odessa))

A
anyd3v, 2014-07-01
@anyd3v

No way. You need a converter and the required format in which your Java application can understand the date, and form it on the js side.

S
Skeeve, 2014-07-03
@Skeeeve

The question is not quite clear, that is, is a Java method called in js? As I understand it: you have an ajax request called on the front end, the method that processes this request takes a parameter of type ava.util.Date? Then maybe this link will help you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question