/    Sign up×
Community /Pin to ProfileBookmark

Calling server-side jsp file from javascript

Hello,

The following code snippets only work with a page that has just been loaded. If I try to go back in the browser cache to the page, the onClick event doesn’t fire anymore, and I’m trying to figure out why. This is running on Linux under Tomcat 1.5.

Here’s my javascript function:

function writeURL(f, url)
{
document.forms[‘frm’+f].action=”../write_url.jsp?url=”+url;
document.forms[‘frm’+f].method=”post”;
document.forms[‘frm’+f].submit();
}

And an example of one of the forms on the page:

<form name=”<%=form_name%>”>
<b><a href=”<%=url%>” onClick=”writeURL(<%=i%>, <%=url%>’);”><%=Entities.encode(title)%></a></b>

And write_url.jsp:

<%@page import=”java.io.*”%>
<%
String url = request.getParameter(“url”);
String strPath = “/mounts/bachman/disks/0/rregalad/url-hits.txt”;
File strFile = new File(strPath);
BufferedWriter objWriter = new BufferedWriter(new FileWriter(strFile, true));
objWriter.write(url);
objWriter.newLine();
objWriter.flush();
objWriter.close();
%>

Help!!!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @JSUser85 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...