I am making a Java web application in whcih customers in different countries are required to upload file through a jsp page.I have to deploy this application in Weblogic server.
Now what i want is their local date-time.I dont want server date-time.
What code should I write in my java application to get their local date and time.
It's tough to get time of user/client unless you pass it explicitly in the post/Ajax call.
Capture time in Javascript and then send it to server in http request.
URL : http://www.w3schools.com/jsref/jsref_obj_date.asp
You should have a look at this question: Determining a web user's time zone. Please see the answer of "JD Isaacks" with a lot of upvotes.
Than you can pass the timezone "offset" to your Java application through an ajax call and use it to calculate the users local date and time.
The only way to get the clients timestamp is to retrieve it on the client and send it to the server.
Using JavaScript() use Date() function and you can send it to server using ajax. You can call this javascript and ajax function right during bodyLoad().
Use following JQuery ajax call function.
$.ajax({
type: "POST",
url: "ServletTest",
data: "clientdate=" + new Date()
});
Try:
<script>
var d = new Date();
alert(d);
</script>
Related
Requirement : Export some data as a csv file when user selects export report as CSV in the browser.
Frontend - Angular 5
Backend - Springboot 1.5.10.RELEASE
We will be generating the report on the server and then sending it to the browser. The report has dates and they need to be shown in the timezone of the browser. Whats the best way to achieve this? Do I have to send the timezone as a URL request param?
You can add a method argumentTimeZone to your controller, then obtain the timezone.
Here is an example:
#RequestMapping
public String foo(..., TimeZone timezone, ...)
{
logger.info("This is the client timezone: " + timezone.getDisplayName());
}
According to Spring Documentation When available, the user’s Time-zone can be obtained by using the RequestContext.getTimeZone() method. As mentioned in comments LocaleContextResolver can be used for getting user time zone.
Note that browser default header doesn't have any client's time zone information. you have to add this information manually.
I just created a web script to get the ticket of Alfresco Share.
Created getticket.get.desc.xml
<webscript>
<shortname>Get User Ticket</shortname>
<description>Personalized greeting</description>
<url>/getticket</url>
<authentication>user</authentication>
<negotiate accept="text/html">html</negotiate>
<negotiate accept="application/json">json</negotiate>
</webscript>
Created getticket.get.html.ftl (Plain Text)
${session.getTicket()}
I am trying to access to it from a Java page. The request is missing some parameters that the web script requires to negotiate the response format. So I need to change my web script to a set response format instead of allowing negotiation. How can I do this?
You can set response format by replacing your negotiation tag lines with following.
extension
There are various response types allowed you can mention one of them json,html,atom are few examples.
Actually i want to use the textbox value and set the session parameter in the same JSP page without submitting it or like using request or response object. This textbox value i want to use in the same JSP page for further use. How can i access the value of a text box in the same page?
You could either utilize the new HTML5 local storage (only supported in the more recent/modern browsers), or you could create a session cookie in JavaScript and store the value in there.
Note that none of those approaches will affect the server side HttpSession in any way. For that you simply can't go around sending a HTTP request containing the desired information, as that's the only way to send information from the client to server side. You could however consider using ajax to send the HTTP request asynchronously and fully transparently in the background.
What is the procedure to get Windows Login Details in java?
Ours is a web application, need to get Windows login username.
any thoughts folks
-PD
In Javascript
var userName='';
var userDomain='';
var wshshell=new ActiveXObject("wscript.network");
//write to some (hidden) form field
with (document.formname) {
userName=wshshell.username;
userDomain=wshshell.userdomain;
}
wshshell=null;
you can pass the variables to hidden parameters and submit them along with form or pass them using ajax. !
This is about as good as you are going to get. It requires the user be using IE.
http://www.rgagnon.com/javadetails/java-0441.html
Can you use
System.getProperty("user.name");
From a web app?
greetings all
i was wondering if it's possible to send some javaScript code in the response of a controller
meaning that i want to invoke a javaScript but not from the jsp (from server side)
something like:
var d = new Date();
var gmtHours = -d.getTimezoneOffset()/60;
var tz=gmtHours;
window.location="page?tz="+tz;
what do you think guys ?
There are two parts to the answer:
Executing JavaScript when the answer comes back from the server. To do that you can wrtite a Javascript in html, something like
<script>
alert("This code just executed");
</script>
usually people have something like
<script>
function init() {
document.getElementsByTagName('input')[0].focus();"
}
window.onload = init;
</script>
It will execute your function when windows loads.
It looks like you want to know the timezone for the user you are displaying results to. As mentioned, HTTP headers don't have this information, so you need to submit it or store as user preference.
If you don't want to store it, you either need to add it to every submit or URL. This way you will always have timezone on server side and you don't need to do 2 round trips.
The workflow might look like this:
1. User submits form or clicks a link -> 2. you form the results on server side -> 3. display results on client side.
Looks like you want to show some dates/times specific to timezone. If you send data to the client using ajax, you can then get it in javascript before step 3 and change it according to your preferences.
If you want to do all the formatting on server side you need to submit the timezone with the original request in step 1.
You can add 2 more steps 1.2 submit timezone request as a response to user action. 1.3 Re-submit the request with timezone info using javascript. This is not optimal, but could work.
I am still not very clear about the question. But it you are asking to invoke a javavscript when a response comes back from server than you can use AJAX and do your processing in the callback.
If you want to access the timezone than another way to send it as part of the parameter right in the beginning as a request parameter itself.