0

Im doing maven rest web application using dojo and java. im newbie to dojoscript

While im submitting the form using xhrpost im getting the particular response objects from the service method into that particular xhrpost function itself so i need to call that xhrpost data to other html pages how can i do that..? im doing login module so i need to display username in all pages which im getting response in xhrpost function..?

this is my dojoscript

    dojo.xhrPost({
    url: "http://localhost:8080/userservices/rest/rest/login",


form: dojo.byId("formNode"),


load: function(newContent,status) {

if(status.xhr.status == 200)
{

alert(newContent); --->which displays username
  window.location.href = "jobseekerdashboard.html";                                                
      }

im getting newContent as my username but i need to display this in some html page how can i do this..?

Kindly help any help will be appreciated more

Thanks Fiyas

1 Answers1

0

You can store the required values in session and retrieve it in all pages wherever required. Say suppose, you want to show the username in all pages when the user is logged in, then this will help

//set the value in your server side
session.setAttribute("userName",userName);

and get the value of the 'userName' attribute from session and show it in jsp.

You can use EL, which is prefered in JSP.

<c:out value="${sessionScope.userName}"/>

For your comment, you can add the username in the response to the querystring like

if(status.xhr.status == 200)
{

alert(newContent); --->which displays username
  window.location.href = "jobseekerdashboard.html?user="+newContent;                                                
      }

then, you can get the parameter from the request url query string using a javascript function. In your case, you just send a single parameter. i.e username

so, your url would be http://localhost:8080/application/jobseekerdashboard.html?user=sam

To get the value of user parameter in the query string, you can do invoke split() on location.search like this below

var username = location.search.split('user=')[1];

thus,username value is sam and you can use it in the new page. if you have more parameters in the querystring, you need to implement a different javascript function.

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • Hi sir thank for the reply but im not using jsp im using html pages with dojoscript and by the way im setting response of username in the status of 200 in service method so how can i access that username in all pages..? using dojoscript? – user2474367 Dec 06 '13 at 10:49
  • Do you have a form which takes you to the next page? – Keerthivasan Dec 06 '13 at 10:56
  • Yes Sir im sending my form using xhrpost and im redirecting from the particular condition to other page – user2474367 Dec 06 '13 at 11:11
  • Hi Sir i did like that exactly its getting the value but how to retrieve the params from querystring into the html page thanks a lot – user2474367 Dec 06 '13 at 11:26
  • you can write a javascript function to retrieve it. How many parameters are you passing in the query string? just username? – Keerthivasan Dec 06 '13 at 11:54
  • http://stackoverflow.com/questions/979975/how-to-get-the-value-from-url-parameter will show you various ways to do it – Keerthivasan Dec 06 '13 at 12:03
  • Hi thanks for the ans im retrieving only username and i need to call username in header.html which is common in all pages so that it displays all pages – user2474367 Dec 06 '13 at 12:25
  • Yes, exactly. Hope you will do it.Please mark answer as accepted so that others will know. if you have anything else, please feel free to ask me – Keerthivasan Dec 06 '13 at 12:28
  • newContent is nothing but a response object so how to store that in memory/dojo and retrieve it in header.html? – user2474367 Dec 06 '13 at 12:38