This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Portals and Portlets and the fly likes JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url" Watch "JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url" New topic
Author

JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url

Ganesh Gadde
Greenhorn

Joined: Sep 23, 2010
Posts: 3
Hello
I have written a sample application using JSF1.2 Core(without using richfaces/myfaces) which is using AJAX inside a Portal Environment(JSR 286,WebSphere Portal 6.1).

I have written java script inside my jsp/.xhtml file which will ajaxify and invoke my servlet and give the response.while constructing the url ,it is getting problematic.I am not getting the status of xmlHttpRequest,able to get the xmlHttpRequest.readyState.Please give me comments/suggestions on this.

this is my .xhtml/jsp

<script type='text/javascript'>
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); //gettime will be the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
}

function handleServerResponse() {
if (xmlhttp.readyState == 4) {

if(xmlhttp.status == 200) {
alert("######## ready state val#########" +xmlhttp.status);
document.myForm.time.value.innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again"+xmlhttp.responseText);
}
}
}
</script>
<body>

<div class="home-container">
<h:form id="myForm">
<f:view>

Server time
<h:inputText id="time"/>

<h:commandLink value="click this button..." onclick="ajaxFunction()"/>
<div id="msg">


xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); // think this line getting problematic

gettime is my servlet class name.I have configured this in web.xml properly

Komari raj
Ranch Hand

Joined: Dec 12, 2008
Posts: 43
Hi ganesh,

check clealry url which is specified in you method as shown in below.

xmlhttp.open("GET","gettime?"+ getdate.getTime(),true);

"gettime?"+ getdate.getTime()" this is wrong url format

you need to include requestparameter variable name with this url....

url="gettime?time="+getdate.getTime();

here time is request parameter for accessing time from jsp to servlet.

i hope this will solve your problam.


Regards
Raju
Ganesh Gadde
Greenhorn

Joined: Sep 23, 2010
Posts: 3
Hi Raj,

Thanks for quick reply.

One of my concern is if i have not used the request paremeter called "time"

then the content should be like this
xmlhttp.open("GET","gettime?"true); //gettime will be the servlet name

is it the rightway,correct me if i was wrong.

-Thanks
Komari raj
Ranch Hand

Joined: Dec 12, 2008
Posts: 43

hi ganesh

please remove '?' from that url as shown in below..




Regards
raju

Ganesh Gadde
Greenhorn

Joined: Sep 23, 2010
Posts: 3
yep.Thanks Raj
Komari raj
Ranch Hand

Joined: Dec 12, 2008
Posts: 43
Welcome Ganesh,


Reagrds
Raj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url
 
Similar Threads
Problem getting servlets working
Notify Users before session expires
Java Dynamic Servlet
A problem in hiding a button
How to Destroy a Session when the user close the browser