using hyperlink to pass parameter
Hi everyone,
pls someone try to help me to solve this problem.
We are designing an application that will let the users download the files from the webpage in which each file internally has a fileid. Now based on that fileid some updations must be done in the database.
The file is dispalyed to the user as a hyperlink.
the coding is
<tr><td><a href="<%=totaldisplayfileName%>"><%=displayfileName%></a></td></tr>
in the above coding"totaldisplayfileName" is the filepath. Now every thing works fine till here. Now I want to update some information in the database once the hyperlink is clicked.
How Can I do that?
As a simple way I tried using onClick event to call a javascript function like
<tr><td><a href="<%=totaldisplayfileName%>" onClick="callThisPage2(fileId)"><%=displayfileName%></a></td></tr>
and the javascript coding is as follows
<script language="javascript">
function callThisPage2(getfileid){
var t = getfileid;
aler(t);
document.dynamicfileid.value = t;//
<%
display(p);
%>
}
</script>
where in the above coding display() is a java function in the same jsp and its coding would be
<%!
public String display(String getfileid)
{
String testfileid = getfileid;
System.out.println("testfileid:"+testfileid);
return testfileid;
}
%>
I got struck in passing the javascript value to the java.What should be done to complete my task? Is any servlet or java bean help needed.If so pls help me with that
[2053 byte] By [
rameshra] at [2007-11-27 9:43:13]

# 4
ok I understand but what actually we are doing is
1. We will keep the files in a server.
2. The totaldisplayfileName will have a value like
"http://ipaddress:appserverport/applicationfolder/temp/downloadfilesfolder/downloadfiles"
So this is how ti works. I have worked very much with jsp could pls help me with codings involving servlet and javascript.
# 5
Ah OK.
Servlets are covered in chapter 3 of Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/
Basically you need to invoke a servlet with a filename as parameter and then in the doGet() do DB actions accordingly and finally stream the file contents to the response. No JS needed in here.
If you really want to use JS with a onclick, consider AJAX to invoke an URI (servlet?) asynchronously. It's a big misunderstanding that you can invoke (serverside) Java classes/methods using (clientside) Javascript.
# 11
Now I am using AJAX to pass the parameters
below is the code that i am using to download a file using a hyperlink
<tr><td><a href="<%=totaldisplayfileName%>" onClick="callThisPage2(<%=displayFileId%>)"><%=displayfileName%></a></td></tr>
In the above coding totaldisplayfileName is the dynamically build filepath that will point to the file which should be downloaded.
Iam fine till file download now In the Onclick event I am calling the following javascript function . I need to open a url as specifed in the below coding but its not working.Can someone pls help me on this
<tr><td><a href="<%=totaldisplayfileName%>" onClick="callThisPage2(<%=displayFileId%>)"><%=displayfileName%></a></td></tr>
<%
}
%>
<script language="javascript">
function callThisPage2(getfileid){
var t = getfileid;
alert(t);
document.selectfile.submit();
document.dynamicfileid.value = t;
var url = 'http://192.168.2.199:7001/beapf/SimpleCounter';
if(window.ActiveXObject){
httpRequest = new ActiveXObject();
}
else{
httpRequest = new XMLHttpRequest();
}
alert(httpRequest.status);
httpRequest.open("GET", url, true);
//httpRequest.onreadystatechange = function() {processRequest(); } ;
httpRequest.send("null");
<%
//display(p);
%>
}
function processRequest()
{
if (httpRequest.readyState == 4)
{
if(httpRequest.status == 200)
{
}
else
{
alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
}
}
}
</script>