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]
# 1

> in the above coding "totaldisplayfileName" is the filepath.

Do I understand it correctly that you're using file paths as hyperlinks? E.g. <a href="file:///c:/foo/bar.exe"> ?

Anyway .. A clean solution for this is to use a servlet which updates the information in DB and then sends the file to the client.

BalusCa at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
you are rght regarding file path. Could you pls help me on this.
rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Do you realize that this would only work if *all* files are already available on the client's system? This is not a download application, but rather a explorer/navigator.Anyway .. Like I said: you need a servlet.
BalusCa at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

BalusCa at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
i understand where i need to look but if you know any sample application simila to that can you provide me a link also a good ajax tutorial link.I am looking for coding help.
rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
i understand where i need to look but if you know any sample application simila to that can you provide me a link also a good ajax tutorial link.I am looking for coding help.
rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Yes....

I agree that using java code to deal with that database mentioned question....

just embed your code in your page by adding

<%@ page language="java" contentType="text/html; charset=${encoding}"

pageEncoding="${encoding}"%>

...

<%

conn=...

stmt=...

rs=...

%>

Puccnda at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
sorry i'm not able to get your idea. could you pls explain littee more eloberately
rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
t
rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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>

rameshra at 2007-7-12 23:48:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...