473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Threads in JSP

Hello Friends

I am developing one project which use only jsp and no beans.

I have to check the database for change in value. If there is a change in the values the page will have to be reloaded.

I prefer to use threds for this background process. But I dont know how to implement threads in jsp. If anybody know please help me via some sample codings.

Thanks for your interest.

By

Sadiq
Mar 13 '07 #1
8 4308
r035198x
13,262 8TB
Hello Friends

I am developing one project which use only jsp and no beans.

I have to check the database for change in value. If there is a change in the values the page will have to be reloaded.

I prefer to use threds for this background process. But I dont know how to implement threads in jsp. If anybody know please help me via some sample codings.

Thanks for your interest.

By

Sadiq
That shouldn't be too much of an issue. Perhaps if you write your thread class somewhere (extend thread) then just create an instance of that thread in the JSP.
Mar 13 '07 #2
I tried creating threaded class seperately as a java program. But it creates one error.

My code is as follows
--------------------------------------------------------------------------------------------------------------------
package dbs;

import java.io.*;
import java.lang.*;
import java.sql.*;

public class Change implements Runnable
{
public void run()
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
Statement st=con.createStatement();
String sql="select * from temp";
ResultSet rs;
try
{
con=DriverManager.getConnection("jdbc:odbc:vr");
rs=st.executeQuery(sql);
if(rs.next())
{
if(rs.getString(1)=="ok")
{
st.executeUpdate("Update temp set id='cancel'");
response.sendRedirect("test1.jsp");
}
}
}
catch(SQLException e1)
{
// System.out.println(e1);
}
catch(InterruptedException e2)
{
}
}
}

--------------------------------------------------------------------------------------------------------------------

When compiling it produces the following error
--------------------------------------------------------------------------------------------------------------------
D:\SADIQ\JSP\DBS>javac Change.java
Change.java:25: cannot resolve symbol
symbol : variable response
location: class dbs.Change
response.sendRedirect("test1.jsp");
^
1 error

--------------------------------------------------------------------------------------------------------------------

Bur I have to redirect the page if the value of the field changes...

Do you know why this error occurs and the way to avoid this..


Thanks for your interest

By

Sadiq
Mar 13 '07 #3
r035198x
13,262 8TB
I tried creating threaded class seperately as a java program. But it creates one error.

My code is as follows
--------------------------------------------------------------------------------------------------------------------
package dbs;

import java.io.*;
import java.lang.*;
import java.sql.*;

public class Change implements Runnable
{
public void run()
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
Statement st=con.createStatement();
String sql="select * from temp";
ResultSet rs;
try
{
con=DriverManager.getConnection("jdbc:odbc:vr");
rs=st.executeQuery(sql);
if(rs.next())
{
if(rs.getString(1)=="ok")
{
st.executeUpdate("Update temp set id='cancel'");
response.sendRedirect("test1.jsp");
}
}
}
catch(SQLException e1)
{
// System.out.println(e1);
}
catch(InterruptedException e2)
{
}
}
}

--------------------------------------------------------------------------------------------------------------------

When compiling it produces the following error
--------------------------------------------------------------------------------------------------------------------
D:\SADIQ\JSP\DBS>javac Change.java
Change.java:25: cannot resolve symbol
symbol : variable response
location: class dbs.Change
response.sendRedirect("test1.jsp");
^
1 error

--------------------------------------------------------------------------------------------------------------------

Bur I have to redirect the page if the value of the field changes...

Do you know why this error occurs and the way to avoid this..


Thanks for your interest

By

Sadiq
That will not work! The response object is available in the JSP not in the thread.

Expand|Select|Wrap|Line Numbers
  1.   if(rs.getString(1)=="ok")
wont work too. When making comparisons use the .equals method. == compares equality of memory locations which is not what you want to compare here.

The thread class and the JSP must be separate files. Is this the thread that is supposed to be checking for changes in the database?
Mar 13 '07 #4
Ok thanks for your answer

If there is any other alternative way to do this page redirection when the value of the field changes.. I need to check the database continuously while the page is running..

I am in urgent need to complete the project within a week..

Tahanks in advance..

By

Sadiq
Mar 13 '07 #5
r035198x
13,262 8TB
Ok thanks for your answer

If there is any other alternative way to do this page redirection when the value of the field changes.. I need to check the database continuously while the page is running..

I am in urgent need to complete the project within a week..

Tahanks in advance..

By

Sadiq
How is the data loaded into the database? The best approach would be to refresh that JSP soon after the data is inserted into the database.
Mar 13 '07 #6
Actually my project is virtual class room

In which staff could be logged in one system and student could be logged in another system.

When student post query, the query and its response from the staff are displayed in seperate window. Whenever the response is recieved a flag field is changed in the databaase.

Whenever the flag changes the window have to be reloaded to display the current data.

So I need the codings...

Thanks for your response

By

Sadiq
Mar 13 '07 #7
hi friend..

if you know about " TimerTask " in java using this method you can check the
DB for a time of period

Hello Friends

I am developing one project which use only jsp and no beans.

I have to check the database for change in value. If there is a change in the values the page will have to be reloaded.

I prefer to use threds for this background process. But I dont know how to implement threads in jsp. If anybody know please help me via some sample codings.

Thanks for your interest.

By

Sadiq
Mar 16 '07 #8
dmjpro
2,476 2GB
u better to use AJAX ....
Mar 16 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.