|
It seems to me that your logic is the wrong way round. A web browser is a client application that requests information form a web server. So your 'client' should be a server, which sends images based on requests from the browser, rather than trying to push them to a browser that is not expecting them.
|
|
|
|
|
Richard MacCutchan wrote: So your 'client' should be a server .....
- I have a 'ServerThread' (one and only one server thread)
- The piece of code that serves images, upon request, is known as 'ClientThread'
- This 'ServerThread' can start N number of 'ClientThread', against N number of requests from web browser.
And YES. Good naming conventions help understand better. 'ClientThread' could better be named as 'RequestThread'.
But the problem still remains. My browser display ONE picture, sent from my server. After that ONE picture, it starts throwing said exception.
|
|
|
|
|
Well, as I suggested above, that is because the browser is not expecting it. Your server thread should only be sending an image when the browser sends it a request.
|
|
|
|
|
Richard MacCutchan wrote: Well, as I suggested above, that is because the browser is not expecting it.
Perhaps I am having tough time understanding you. Please bear with me. To the best of my knowledge, I am sending only the images and nothing else. I also tried removing the header just before I transmit the image, even that does not help. 
|
|
|
|
|
At the risk of repeatedly repeating myself ...
You cannot send unsolicited messages to a web browser, they do not work that way.
|
|
|
|
|
THIS IS MY CODE BUT IT IS NOT GIVING THE RIGHT OUTPUT
package main;
import java.util.*;
public class Year_Conversion {
public static void main(String[] args) {
String s1;
System.out.println("Input string in the following format dd-mm-yy:");
Scanner sc=new Scanner(System.in) ;
s1=sc.next();
convertDate(s1);
}
public static String convertDate(String s1)
{
String ans = null;
String[] parts=s1.split("-");
int d=Integer.parseInt(parts[0]);
int m=Integer.parseInt(parts[1]);
int y=Integer.parseInt(parts[2]);
if(d<10)
{
ans=ans+"0"+d;
}
else
{
ans=ans+d;
}
if(m<10)
{
ans=ans+"0"+m;
}
else
{
ans=ans+m;
}
ans=ans+"19"+y;
return ans;
}
}
|
|
|
|
|
What output do you get?
Rather than convert to integer to determine if you need to prefix a zero why not use strings length, if it is 1 you need a zero...
|
|
|
|
|
1) DON'T SHOUT! Typing in all capitals on the internet is considered shouting. Typing your entire message in capitals is rather rude.
2) If you want someone to help you get the "right output", then you need to tell us what the "right output" is.
Show us several examples of what you type in, what the expected output is, and what the actual output is.
Without that information, we can't help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Member 13276968 wrote: String ans = null;
Should be empty string not null
Also noting that the code you have is not printing the result.
|
|
|
|
|
Dear experts,
I understand now that I have to get Generated Key in order to obtain my auto-incremental Id from a table.
However, after getting the generated key and set it to the model. I am stuck as to how to give it to my third table.
public void insertTutor(tutor m) throws MyDataException {
openConnection();
try {
connection.setAutoCommit(false);
} catch (SQLException e1) {
e1.printStackTrace();
}
String qry = INSERT_QRY;
try (
PreparedStatement ps = connection.prepareStatement(qry)) { ;
ps.setString(1, m.getName());
ps.setString(2, m.getNRIC());
ps.executeUpdate();
ResultSet tableKeys = ps.getGeneratedKeys();
tableKeys.next();
int tutor_id = tableKeys.getInt(1);
m.setTutor_id(tutor_id);
System.out.println(tutor_id);
connection.commit();
} catch (SQLException e) {
e.printStackTrace();
....
}}}}
And I do the same for my 2nd table.
My third table I need to make use of the Ids from the first and 2nd table.
So, do I create an insert like this ?
String qry = "INSERT INTO project.tutor_subject" + "(tutor_id, sub_id) values"
+ "(?,?)";
And how do I go about doing the third DAOImpl and the controller to get the Ids to go into the third table ?
I have read that JPA and using MyBatis is better for many to many table insertion.
Should I do it via JPA and MyBatis ?
|
|
|
|
|
karengsh,
It looks like you have most of your framework built out already, but JPA or MyBatis could also be used if you wish.
The advantage of using JPA is it handles almost all of the boilerplate database CRUD operations, but there is a learning curve to using it.
If you wish to continue on your current path, don't worry about a DAO for the tutor_subject join table, just put the logic in a manager class for the tutor entity.
Given the pattern I see in your code, you would simply use the getId() methods on the objects passed to your insertTutor and insertSubject methods
tutor tmpTutor = new tutor("Fred Flintstone","NRIC value");
subject tmpSubject = new subject("Java");
boolean success = false;
try {
insertTutor(tmpTutor);
insertSubject(tmpSubject);
success = true;
}
catch (MyDataException mde){
}
if (success){
try {
associateTutorToSubject(tmpTutor.getId(), tmpSubject.getId());
}
catch (MyDataException mde2){
}
}
|
|
|
|
|
Hi Mike,
My problem is how do I make the tmpTutor.getId() and tmpSubject.getId() mehtod static so that I could implement in my controller ?
Cos right now, I can only insert the tutorDAOImpl when I do the preparedStatement for tutor.
When I want to do the associateTutorToSubject, I can't do it the way like yo said cos tutorDAOImpl and SubjectDAOImpl are both separate classes. And so there is no way for the controller to read the getId from the tutorDAOImpl etc.
|
|
|
|
|
when i select jcombobox the database should retrieve in Jtable
|
|
|
|
|
Yes, it should. And if it doesn't it's a very naughty boy.
|
|
|
|
|
|
I try to bring a sense of perspective sometimes. 
|
|
|
|
|
Hi! I am learning servlet, can someone kind enough to explain where to place the username, password, address, and port to be used in connection to a MySQL database in WAMP instead of placing it in the code? So that if the address of MySql or server is changed I will not have to change the code. Take the succeding as an example, "jdbc:mysql://localhost:3306/sonoo","root","root"). I am thinking if they are written in the code and they will be changed like the password for mysql will be changed, I will have to change the code. Thus, where will I put the localhost, 3306, sonoo, root, and root so that I will not change the code everytime the address and password, etc. will change. I am using netbeans and apache tomcat. Thank you so much.
|
|
|
|
|
|
How can I change tempo of a jetfile in android?
|
|
|
|
|
|
public class Try_Array
{
public void cool(int[] a)
{
Second_Arra(a);
First_Array(a);
}
private void First_Array(int[] a )
{
for (int i = 0; i < a.length; i++)
a[i] = 10;
}
private void Second_Arra(int[] a )
{
for (int i = 0; i < a.length; i++)
a[i] = 100;
}
}
public class ArrayDemo
{
public static void main(String[] args){
int[] a = {99, 5, 4, };
Try_Array=new Try_Array();
Obj.cool(a);
System.out.println("Array values after sorting:");
for (int i = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}
}
the Output :
Array values after sorting:
100 100 100
why Java Invoke First_Array(a) not Second_Arra(a); I got confuse !!!!! did java chose random method or what !
|
|
|
|
|
I cannot see how you can get any results, since that code will not even compile.
|
|
|
|
|
it's work fine the output :
Array values after sorting:
10 10 10
so my question how java invoke First_Array(a); not Second_Arra(a) ,
|
|
|
|
|
I copied the code from your question and it definitely does not compile.
|
|
|
|
|
public class ArrayDemo
{
public static void main(String[] args){
int[] a = {99, 5, 4, };
Try_Array Obj =new Try_Array();
Obj.cool(a);
System.out.println("Array values after sorting:");
for (int i = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}
}
public class Try_Array
{
public void cool(int[] a)
{
Second_Arra(a);
First_Array(a);
}
private void First_Array(int[] a )
{
for (int i = 0; i < a.length; i++)
a[i] = 10;
}
private void Second_Arra(int[] a )
{
for (int i = 0; i < a.length; i++)
a[i] = 100;
}
}
Ok Sorry my Mistake , i fix it now , why and how java invoke First_Array(a); not Second_Arra(a); is that random , I got confuse
|
|
|
|