Hi All,

I am creating an application in which I want to keep refreshing a jsp file and in that jsp file i need to keep calling another url of type and save this url in database. Here the url keeps changing in every second ie. values of a & b keeps changing.

I have been able to keep refreshing the jsp file but unable to call another dynamic url in it. Please tell me how to do it in my jsp.

Thanks in advance for your help.

Dani AI

Generated

Short answer for : do not rely on a JSP page refresh to perform repeated network I/O. JSPs are for presentation; network calls and DB writes belong in server-side code (a servlet, a scheduled task or a background worker). was right to ask where the values come from — if you don't know a and b you must fetch the remote resource and extract them (from a redirect Location header or by parsing the response body).

A practical approach:

  • Create a scheduled background task (ScheduledExecutorService or Quartz) that runs every second (or whatever interval you need).
  • From that task, open an HTTP connection to the target endpoint with sensible timeouts, inspect the response (or headers) to obtain the a and b values, then persist the final URL or the parsed parameters using a pooled JDBC DataSource and a prepared statement.

Example sketch (conceptual):

ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(() -> {
    try { pollAndSave(); } catch (Exception e) { /* log and back off on repeated failures */ }
}, 0, 1, TimeUnit.SECONDS);

/* pollAndSave(): open HttpURLConnection with timeouts, inspect response or Location header for query string,
   parse parameters (URLDecoder), then call saveUrlToDb(parsedUrl) which uses a DataSource + PreparedStatement. */

Production notes and cautions: use a connection pool (do not open raw connections every second), validate and URL-decode parameters before inserting, add retry/backoff and error logging, respect the remote server’s rate limits (one request per second can be heavy), and avoid doing this work on HTTP request threads. If the intent was a browser-side call, remember cross-origin AJAX will be blocked unless the remote side allows CORS — in that case proxy the request through your server.

Recommended Answers

All 6 Replies

Can't you put variables in the values of your url? How do you create that url and how did you put in your code?

Can't you put variables in the values of your url? How do you create that url and how did you put in your code?

The url is a web page where the value of a & b keeps changing every second. If I put the values in variables then how will I fetch it's value as I can't know values of a & b.

If you don't know what are those values, then how could we know? Don't you have a way to read them from somewhere?

If you don't know what are those values, then how could we know? Don't you have a way to read them from somewhere?

The names of the variables a & b are fixed but not their values. The values are dynamic, like we have in most of the cases.

I have no idea.

I have no idea.

no problem.
Somebody else please help me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.