 |
 |
Index ‹ java-programmer
|
- Previous
- 3
- Java server performance - jeetyHi All,
I am working on an application where a servlet need to handle min 600
request / sec(which will keep on increasing in future)
So I am not able to decide which application server I should use.
As I go through some benchmarks I came to know that Jetty's performance
is better but
I don't know how much load it can handle.
Is there any who has used Jetty on heavy traffic application?
or is there any another servlet container / HTTP Server which can
handle such a load
Plz suggest me.
Thanks in Advance.
Rajiv Girdhar
- 8
- Java securityI havean applet that connects to Oracle osing the thin client. It
works when run from IDE. When I try to load it into a web browser I
get
java.security.AccessControlException: access denied
(java.util.PropertyPermission oracle.jserver.version read)
What's up?
- 8
- Array of generic List?Hello,
I am new to 1.5 and thus generics. I have read the generic tutorial and
a decent number of websites/newsgroup posts on the subject. But I still
cannot find a satisfactory solution to the following (as of now the
best I've got is an unchecked conversion warning)
The code below does not compile, but I think it shows to a human what I
want to accomplish. I can't seem to find the proper syntax and use of
generics to accomplish this without a warning. Any help and reasoning
why I need to do whatever the solution is would be great. Thanks.
public class MyClass {
private List<Foo>[] myFoos;
public MyClass() {
myFoos = new List<Foo>[5];
}
public void addFoo(int index, Foo foo) {
myFoos[index].add(foo);
}
}
- 9
- Question on the flush methodAccording to Sun's web site, the flush method of the OutputStream object
does nothing.
So, what does actually happens when you call it?
At times I may see different behavior when including it within a program
(some times a socket read error) which I would think is strange esspecially
if the method is not supposed to do anything.
Any ideas?
- 10
- Help with writing simple parser for HTML/XMLI'm having trouble getting started with coding a simple parser and prototype
for my application.
The parser needs to parse HTML & XML pages to strip the tags and return just
the data. Ive read thru sevral java refeerence books but seem to be having
trouble getting started with the code.
I'd be gratefull for a push in the right direction.
thanks
sal
ps this is my final year University Computer Science project
for more details on the project
http://www.mellowmoose.org/project.html
- 10
- 10
- Need help creating a program to create sudukoStill a little rough at this language but i need to create a program
for my class. Was wanting to create a java program that makes sudukos.
It doesn't need a GUI or anything like that just ouput to a txt file
ot to the screen. I would appreciate any help or direction.
- 10
- thin java cient?Hello, please, I'm searching for a Thin Java Client, for J2EE.
I want to build a thin java swing client.
How to do it?
tks
Programador
----------------------------------
email***@***.com
- 10
- 10
- 10
- Novice Form QuestionI am a novice at JSP / HTML and have a Forms releated question. I am
really looking for sample code I can leverage to help understand how
to address non-trivial form layouts.
I undestand the how to build a -simple- form with a few input fields
and process this with JSP - Struts interaction. Unfortunately, I am
weak in HTML / JavaScript and I need to understand and build a more
complicated form.
Basically my form must look something like this:
User Name: _________________ Baggage Type ____________
Add Button | Remove Button Add Button | Remove Button
---------------------------- -------------------------
| Tom | | SomeBagType 1 |
| Dick | | SomeBagType 2 |
| Harry | | SomeBagType 3 |
| Jane | | SomeBagType 4 |
| | | |
---------------------------- -------------------------
Submit Button Cancel Button
Note that there are 6 buttons on the form. The Add / Remove buttons
are intended to allow the user to Add or Remove -User name's- or
-Baggage Type's- before the form is submitted.
I am not sure how to handle this. My guess is that Javascript might
work ( I do Java but not JavaScript :-( ) but I am open to suggestions
and most importantly EXAMPLES of how this might be implemented.
This code will part of a JSP-Struts project.
Thanks.
- 11
- Saving canvasHi. I have a problem with saving canvas to file. All over net there
are faqs on how to save a NEW canvas to file (after drawing on it). I
have a canvas, what should i do in order to save what's currently on
it to a file?
- 12
- internet address vs lanI am about to create a RPC program and I need a servlet to talk to a
server. The servlet is running on the internet, the server is running
on a lan computer. I am pretty sure that the lan ip address is behind
our firewall. Can I still communicate with the server through RPC.
Berlin Brown
email***@***.com
this question sounds confusing, doesnt it?
- 13
- Anyone seen this problemMaybe I am being stupid, but I am having difficulty getting mouse events
from a custom JComponent. At this point I have put an instance of a subclass
of JComponent in a JScrollPane and placed it in the center of a
BorderLayout. I then added a mouse listener to the subclass of JComponent,
traced through the code to make sure I am acutally adding the listener, but
my mouseClicked(), mousePressed() and mouseReleased() methods on my listener
class are not called. Any one seen this problem before.
- 13
- XML call XSL that calls xml through document() elementHello,
I am trying to create an XML document on the fly that sends some
parameters to an xsl document which calls the correct xml document that
corresponds to the parameters.
I reference the xsl document:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="web-primary.xsl"?>
I am just trying to hardcode the request to prove that this is possible
for the time being so the parameters are already in the xsl that will
eventually be variables.
but I am unsure what else to include in the first XML file to make the
call to the web-primary.xsl????? My XSL is complete and the
corresponding XSL files are complete.
The xsl doc has a document element that calls the correct xml file that
contains the data.
My reason for doing all of this is because Firefox will not allow me to
go to a remote xml file from the server so I want the browser to do the
work of getting the remote xml file. If you have a better way of doing
this, please let me know.
thx.
|
| Author |
Message |
programwiz08

|
Posted: 2004-7-27 23:05:00 |
Top |
java-programmer, Java program help
Hello everyone, I need your help.. can you check why did i commit an
error on the n=System.read("enter numer:"); part...? Thanks in
advance...
By the way, the program will run as follows:
the user will input a number, and the program will generate the
fibonacci series based on the number. if example user input is 4,
there should be four series of fibonacci...:)
public class fibonacci
{
public static void main(String args[])
{
int prev1 = 1, prev2 = 1, current = 1;int n;
n = System.read("enter number: ");
for (int i = 3; i <= n; i++)
{
current += prev2;
prev2 = prev1;
prev1 = current;
System.out.println(" " + current);
}
}
}
|
| |
|
| |
 |
Claudio Alberto Andreoni

|
Posted: 2004-7-27 23:31:00 |
Top |
java-programmer >> Java program help
Maybe because a method called int System.read(String)
I think you have to use the methods of the InputStream System.in.
You can do something like this:
java.io.BufferedReader br = new java.io.BufferedReader(new
java.io.InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Pats wrote:
> Hello everyone, I need your help.. can you check why did i commit an
> error on the n=System.read("enter numer:"); part...? Thanks in
> advance...
> By the way, the program will run as follows:
> the user will input a number, and the program will generate the
> fibonacci series based on the number. if example user input is 4,
> there should be four series of fibonacci...:)
>
> public class fibonacci
> {
>
>
> public static void main(String args[])
> {
> int prev1 = 1, prev2 = 1, current = 1;int n;
> n = System.read("enter number: ");
> for (int i = 3; i <= n; i++)
> {
> current += prev2;
> prev2 = prev1;
> prev1 = current;
> System.out.println(" " + current);
> }
>
> }
> }
|
| |
|
| |
 |
Claudio Alberto Andreoni

|
Posted: 2004-7-27 23:31:00 |
Top |
java-programmer >> Java program help
Claudio Alberto Andreoni wrote:
> Maybe because a method called int System.read(String) does not exist.
> I think you have to use the methods of the InputStream System.in.
> You can do something like this:
> java.io.BufferedReader br = new java.io.BufferedReader(new
> java.io.InputStreamReader(System.in));
> int n = Integer.parseInt(br.readLine());
>
> Pats wrote:
>
>> Hello everyone, I need your help.. can you check why did i commit an
>> error on the n=System.read("enter numer:"); part...? Thanks in
>> advance...
>> By the way, the program will run as follows:
>> the user will input a number, and the program will generate the
>> fibonacci series based on the number. if example user input is 4,
>> there should be four series of fibonacci...:)
>>
>> public class fibonacci
>> {
>>
>>
>> public static void main(String args[])
>> {
>> int prev1 = 1, prev2 = 1, current = 1;int n;
>> n = System.read("enter number: ");
>> for (int i = 3; i <= n; i++)
>> {
>> current += prev2;
>> prev2 = prev1;
>> prev1 = current;
>> System.out.println(" " + current);
>> }
>>
>> }
>> }
|
| |
|
| |
 |
r9937

|
Posted: 2004-10-26 19:24:00 |
Top |
java-programmer >> Java program help
Answers in programming language : Java
Question 1: Explain the difference between the following modifiers
through examples:
?Abstract
?Final Class
?Public
Question 2: Through a small example, Explain the following:
i) Concept of Subclasses, Super classes and Inheritance
ii) What is the name of the top most class in the Java and where it
is defined
Question 3: List and explain the main features of Java (for e.g.
multi-threading) and identify the classes/package through which they
are supported.
This is a Project Assignment. Answer the following question using
Java.
Suppose that you have to computerize a car show room which keeps the
latest models of cars, and provides post sales services to customers.
(i) List all important classes, their data structures and other
attributes.
(ii) Draw an inheritance diagram for the entire application which
should comprise of base classes and sub-classes.
(iii) Implement at least 3 modules.
(iv) Describe different reports to be produced by the programmer.
i am bca student need answers as earlest as possible help me iwill
thank full to those who will help me
thankyou
|
| |
|
| |
 |
Joona I Palaste

|
Posted: 2004-10-26 20:51:00 |
Top |
java-programmer >> Java program help
rohit srivastava <email***@***.com> scribbled the following:
> Answers in programming language : Java
> Question 1: Explain the difference between the following modifiers
> through examples:
> ?Abstract
> ?Final Class
> ?Public
> Question 2: Through a small example, Explain the following:
> i) Concept of Subclasses, Super classes and Inheritance
> ii) What is the name of the top most class in the Java and where it
> is defined
> Question 3: List and explain the main features of Java (for e.g.
> multi-threading) and identify the classes/package through which they
> are supported.
> This is a Project Assignment. Answer the following question using
> Java.
> Suppose that you have to computerize a car show room which keeps the
> latest models of cars, and provides post sales services to customers.
> (i) List all important classes, their data structures and other
> attributes.
> (ii) Draw an inheritance diagram for the entire application which
> should comprise of base classes and sub-classes.
> (iii) Implement at least 3 modules.
> (iv) Describe different reports to be produced by the programmer.
> i am bca student need answers as earlest as possible help me iwill
> thank full to those who will help me
> thankyou
How about doing your homework yourself? Sheesh, the way you copied
your assignment word-for-word doesn't make it look like you intend to
bother trying it yourself at all. What do you think you're in school
for, anyway?
--
/-- Joona Palaste (email***@***.com) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"As a boy, I often dreamed of being a baseball, but now we must go forward, not
backward, upward, not forward, and always whirling, whirling towards freedom!"
- Kang
|
| |
|
| |
 |
zutroi

|
Posted: 2004-11-8 7:02:00 |
Top |
java-programmer >> Java program help
Andrew Thompson wrote:
> <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#field_summary>
>
> [ you would get a much longer and better answer
> on c.l.j.help, I assure you.. ]
thankyou for the pointer. luckily i have subscribed to c.l.j.help
already. can i ask one question of you? what is the charter of
c.l.j.programmer? i would have thought that if you had a java
programming question that this might be an apporopriate place to start?
correct me if i'm wrong, and i know that you will :-)
--
bob (rdr00)
Outgoing mail is NOT certified Virus Free.
For all I know, there's a dirty big fsckin' virus stuck onto
the end of this message and if you're using a Microsfot product,
then I'd say that you're fscked.
|
| |
|
| |
 |
Chris Smith

|
Posted: 2004-11-8 8:20:00 |
Top |
java-programmer >> Java program help
zutroi wrote:
> thankyou for the pointer. luckily i have subscribed to c.l.j.help
> already. can i ask one question of you? what is the charter of
> c.l.j.programmer? i would have thought that if you had a java
> programming question that this might be an apporopriate place to start?
> correct me if i'm wrong, and i know that you will :-)
The charter for .programmer is:
This unmoderated group is for problems and discussion relating to
Java as a language, programming in general and the application of
libraries and APIs not covered under other groups.
If traffic is high enough, this group may later be split
functionally. In the meantime, posts specific to a class or package
should include its name at the beginning of the title, for example,
[awt], [sun.net], etc., to facilitate easy filtering.
That's all academic, though. There is no mechanism to update a charter
for a Big-12 newsgroup, and as a result charters rarely describe the
actual usage of groups. Lurking is encouraged to determine that. For
example, .help is quite frequently used for involved programming
questions, despite its charter that encourages mostly setup/install
questions and only the most simple of programming problems.
There's currently a vague understanding that "beginner" questions go to
.help and "advanced" questions go to .programmer. Nevertheless, there's
never really been a determined effort in the past to sort traffic to the
correct groups. Andrew has attempted to start such an effort in the
past year or so, and a few other people have jumped on the bandwagon.
I'm of the opinion that it does more harm than good, especially when (as
has occasionally been the case recently) it causes people to feel
justified in being rude to new posters.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2004-11-8 11:55:00 |
Top |
java-programmer >> Java program help
On Sun, 07 Nov 2004 23:02:15 GMT, zutroi wrote:
> what is the charter of c.l.j.programmer?
Pretty much what Chris said, ..but since I have an URL.
<http://www.physci.org/codes/javafaq.jsp#groups>
Note the caveats that Chris added. Ultimately a group
is shaped by the contributors.
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
| |
|
| |
 |
somekid413

|
Posted: 2006-1-13 4:57:00 |
Top |
java-programmer >> Java program help
Hi, I have to write the following program for class...and I have no idea
where to start
if anyone would be so kind as to point me in the right direction (or write
the program) i would be very appreciative
1. Write a class named Pupil that implements Comparable. It has four
instance variables of type String and double (Name, testl, test2, test3, and
average). The constructor must input the test scores from the user, and call
the computeAverage method to initialize the instance variable, average. In
addition, the class must have getters for each instance variable. It must
also have a private helper method called computeAverage that returns the
average of all three test scores. And a compareTo method that compares two
students. It must work like all compareTo methods such that it takes in an
Object parameter and returns 1 if the object that called it is greater
returns -1 if they are equal, it returns 0.
2. Create a TestPupil class (must put import Java.lang; at the top) that
prompts the user for the number of students in the class prompts the user to
enter the information about all students in the class and creates a student
object for each pupil. Stores the students in an arrayList and calls the
compareTo method which compares all the students to all the other students in
the class
Thanks
-A
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2006-1-13 5:48:00 |
Top |
java-programmer >> Java program help
somekid413 wrote On 01/12/06 15:56,:
> Hi, I have to write the following program for class...and I have no idea
> where to start [...]
The instructions seem pretty straightforward, so if you
have no idea where to start you must be having pretty serious
trouble with the class. I strongly recommend that you talk
with your professor about the difficulties you're having; you
may need some extra tutoring. Do it now, while the semester
is still young: In the early going your professor may be able
to help you overcome your problems and catch up, but if you
just sit there comprehending nothing and letting the class
wash over you, the professor may not become aware of how far
behind you are until you're so far behind there's no hope.
The professor wants you to learn -- so if you want to
learn, go have that talk. Now!
> if anyone would be so kind as to point me in the right direction (or write
> the program) i would be very appreciative
I see that the "if you want to learn" is not exactly
a tautology.
--
email***@***.com
|
| |
|
| |
 |
IchBin

|
Posted: 2006-1-13 14:38:00 |
Top |
java-programmer >> Java program help
somekid413 wrote:
> Hi, I have to write the following program for class...and I have no idea
> where to start
> if anyone would be so kind as to point me in the right direction (or write
> the program) i would be very appreciative
>
> 1. Write a class named Pupil that implements Comparable. It has four
> instance variables of type String and double (Name, testl, test2, test3, and
> average). The constructor must input the test scores from the user, and call
> the computeAverage method to initialize the instance variable, average. In
> addition, the class must have getters for each instance variable. It must
> also have a private helper method called computeAverage that returns the
> average of all three test scores. And a compareTo method that compares two
> students. It must work like all compareTo methods such that it takes in an
> Object parameter and returns 1 if the object that called it is greater
> returns -1 if they are equal, it returns 0.
> 2. Create a TestPupil class (must put import Java.lang; at the top) that
> prompts the user for the number of students in the class prompts the user to
> enter the information about all students in the class and creates a student
> object for each pupil. Stores the students in an arrayList and calls the
> compareTo method which compares all the students to all the other students in
> the class
>
> Thanks
> -A
Apparently your are not paying for you eduction. So how much is it worth
to you for me to write it for you...
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- storing SecretKey in keystorehi
i created a keystore as below
public static void makeKeyStore(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null,"".toCharArray());
FileOutputStream ksout=new FileOutputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.store(ksout, password);
Arrays. fill(password, '\u0000' ) ;
}
catch(Exception e){
e.printStackTrace();
}
}
then i tried to store a generated key using an alias
public static void putEntriestoKS(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());;
FileInputStream fin=new FileInputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.load(fin,password);
FileOutputStream fout=new FileOutputStream("myks.keystore");
KeyGenerator kg=KeyGenerator.getInstance("AES");
SecretKey skey=kg.generateKey();
ks.setKeyEntry("mysecretkey", skey, password,null);
ks.store(fout,password);
Arrays.fill(password,'\u0000');
}
catch(Exception e){
e.printStackTrace();
}
}
when i run this i am getting a java.security.KeyStoreException: Cannot
store non-PrivateKeys
How then can i store SecretKey ?Do i have to use another provider?can
someone explain?
thanks
Jim
- 2
- ports/77656: java/jdk15 - (AMD64) install problem.Synopsis: java/jdk15 - (AMD64) install problem.
State-Changed-From-To: open->feedback
State-Changed-By: linimon
State-Changed-When: Fri Mar 31 08:53:35 UTC 2006
State-Changed-Why:
Submitter: is this still a problem?
Responsible-Changed-From-To: phantom->freebsd-java
Responsible-Changed-By: linimon
Responsible-Changed-When: Fri Mar 31 08:53:35 UTC 2006
Responsible-Changed-Why:
Reassign from phantom since he has been inactive for more than one year.
Hat: gnats-admin
http://www.freebsd.org/cgi/query-pr.cgi?pr=77656
- 3
- Applet startup error - simple questionGreetings!
I am running into a very strange problem with a very simple code
In my html page I have the following code:
<applet codebase="/" code="InterApplet" width="400" height="150"
name="InterApplet">
<param name="OutFrame" value="outFrame" valuetype="object">
no support for java
</applet>
When I load the page on Windows 2000 machine running IE6 it works fine
- applet loads. However, when I try to open this page on a Windows XP
machine also running IE6 it can't find the applet "load: class
InterApplet not found". I have my custom built web server so I could
actually see that the browser did make a request for InterApplet.class
and web server has served it.
So what in the world is happening?!? This is very frustrating.
I have not done any serious java programming since '97...
Thanks for your time.
- 4
- 2 level RAMAt some it will be economic to create banks of say 10 gigabytes of
RAM. This ram will be slower than regular RAM, but won't lose its
value when the power is ostensibly off.
How will this be integrated into Java?
The Windows world will likely treat these as small disk drives. You
will be able to manually place important files there. Windows will
fill it with something useless like system recovery snapshots.
However, it could be used more cleverly.
1. as a cache, much like the old Univac 1106 migrated files between
various speeds of mass storage in order to keep the most commonly used
ones on the fastest devices. You might even, like the 1106 unify this
with backup, so all files got backed up to servers on the Internet, or
spilled there if the disk became full.
2. for large address spaces, to keep infrequently used objects. It
becomes like your swap file today.
3. something else.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
- 5
- Writing and running files from a Java/AspectJ application.I'm creating an add-on to windows that will let me create files and run
basic functions such a image editing, both built in and on the hard
drive of a ftp server. If anyone could help me it would be wonderful.
I am planning to use the Eclispe SDK woth the AspectJ plugin. I have
the basic functions set up word editing but I need to know how to run
.exe files on the hard drive.
- 6
- 7
- SPOT smart sensorsFor anyone interested in these but could never get the willpower to
learn embedded C or somesuch arcane language, these kits from Sun just
came out:
http://www.sunspotworld.com/products/
Some info:
http://www.sunspotworld.com/docs/
I had tinkered around with these typrs of objects before, but having
the thing programmable in Java makes the entire thing easier on my
end :-)
- 8
- Client/Server chat program - wait for connectionHi,
I'm trying to modify a client/server chat program that connects
immediately, to wait till an IP address is selected from a combo box and
then connect when a connect button is pressed. The combo box is loaded
from a file of IP addresses and I select the localhost address of
127.0.0.1.
I've taken out the app.runClient line from the main class and made it
the actionPerformed when the connect button is pressed, but the client
side seems to go dead (won't accept any input) when I do this although
the connection seems to be working.
Any help appreciated.
// Client.java
// Set up a Client that will read information sent
// from a Server and display the information.
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Client3 extends JFrame
{ private JTextField enter;
private JTextArea display;
private JButton connect, send;
private JComboBox selectIp;
ObjectOutputStream output;
ObjectInputStream input;
String message = "", address = "";
public Client3()
{
super( "Client" );
Container c = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout( new GridLayout( 2, 1, 3, 3 ) );
// Enter field and action listener
enter = new JTextField();
enter.setEnabled( false );
enter.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
sendData( e.getActionCommand() );
}
}
);
northPanel.add( enter );
// Send button
send = new JButton("Send >");
send.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
sendBtn( e.getActionCommand() );
}
}
);
northPanel.add( send );
c.add( northPanel, BorderLayout.NORTH );
// Dislay area
display = new JTextArea();
c.add( new JScrollPane( display ),
BorderLayout.CENTER );
JPanel southPanel = new JPanel();
southPanel.setLayout( new GridLayout( 1, 2, 3, 3 ) );
// SelectIP combobox, listener and item listener
selectIp = new JComboBox();
selectIp.addItemListener(
new ItemListener() {
public void itemStateChanged( ItemEvent evt )
{
if( evt.getSource() == selectIp )
if( evt.getStateChange() == ItemEvent.SELECTED )
address = (String) evt.getItem();
}
} );
southPanel.add( selectIp );
// Read file and load into combobox
try
{
BufferedReader inBuffer = new BufferedReader( new
FileReader("ipaddress.txt") );
String line = inBuffer.readLine();
while( line != null )
{
selectIp.addItem( line );
line = inBuffer.readLine();
}
inBuffer.close();
}
catch(IOException e)
{ System.out.println(e);
}
// Connect button
connect = new JButton( "Connect");
connect.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
{
if( e.getSource() == connect )
{
runClient();
}
}
} );
southPanel.add( connect );
c.add( southPanel, BorderLayout.SOUTH );
setSize( 300, 300 );
show();
} // end Client constructor
public void runClient()
{ Socket client;
try {
// Step 1: Create a Socket to make connection.
display.setText( "Attempting connection\n" );
client = new Socket(
InetAddress.getByName( address ), 6000 );
display.setText( "Connected to: "+ address +
client.getInetAddress().getHostName() );
// Step 2: Get the input and output streams.
output = new ObjectOutputStream(
client.getOutputStream() );
output.flush();
input = new ObjectInputStream(
client.getInputStream() );
display.append( "\nGot I/O streams" );
// Step 3: Process connection.
enter.setEnabled( true );
do
{ try {
message = (String) input.readObject();
display.append( "\n" + message );
display.setCaretPosition(
display.getText().length() );
}
catch ( ClassNotFoundException cnfex ) {
display.append(
"\nUnknown object type received" );
}
} while ( !message.equals( "SERVER>>> quit" ));
// Step 4: Close connection.
display.append( "\nClosing connection.\n" );
output.close();
input.close();
client.close();
} // end try
catch ( EOFException eof ) {
System.out.println( "Server terminated connection" );
}
catch ( IOException e ) {
e.printStackTrace();
}
} // end runClient
// Action handler for Enter key
private void sendData( String s )
{
try {
message = s;
output.writeObject( "CLIENT>>> " + s );
output.flush();
display.append( "\nCLIENT>>>" + s );
}
catch ( IOException cnfex ) {
display.append(
"\nError writing object" );
}
} // end sendData
// Action handler for send button
private void sendBtn( String s )
{
try {
s = enter.getText();
output.writeObject( "SERVER>>> " + s );
output.flush();
display.append( "\nSERVER>>>" + s );
}
catch ( IOException cnfex ) {
display.append(
"\nError writing object" );
}
} // end sendBtn
// Main
public static void main( String args[] )
{
Client3 app = new Client3();
app.addWindowListener(
new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{ System.exit( 0 );
}
}
);
// app.runClient();
} // end main
} // end Client Class
// Server.java
// Set up a Server that will receive a connection
// from a client, send a string to the client,
// and close the connection.
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Server1 extends JFrame
{
private JTextField enter;
private JTextArea display;
ObjectOutputStream output;
ObjectInputStream input;
public Server1()
{
super( "Server" );
Container c = getContentPane();
enter = new JTextField();
enter.setEnabled( false );
enter.addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
sendData( e.getActionCommand() );
}
}
);
c.add( enter, BorderLayout.NORTH );
display = new JTextArea();
c.add( new JScrollPane( display ),
BorderLayout.CENTER );
setSize( 300, 300 );
show();
} // end Server constructor
public void runServer()
{
ServerSocket server;
Socket connection;
int counter = 1, optionPane;
try {
// Create a ServerSocket.
server = new ServerSocket( 6000, 100 );
while ( true )
{
// Wait for a connection.
display.setText( "Waiting for connection\n" );
connection = server.accept();
display.append( "Connection " + counter +
" received from: " +
connection.getInetAddress().getHostName() );
// Set input and output streams.
output = new ObjectOutputStream(
connection.getOutputStream() );
output.flush();
input = new ObjectInputStream(
connection.getInputStream() );
display.append( "\nGot I/O streams\n" );
// Process connection.
String message =
"SERVER>>> Connection successful\n";
output.writeObject( message );
output.flush();
enter.setEnabled( true );
do {
try {
message = (String) input.readObject();
display.append( "\n" + message );
display.setCaretPosition(
display.getText().length() );
}
catch ( ClassNotFoundException cnfex ) {
display.append(
"\nUnknown object type received" );
}
if( message.equals( "CLIENT>>> TRANSFER FILE?" ) )
{
optionPane = JOptionPane.showConfirmDialog((Component)
null, "Do you want to accept the file transfer",
"File Transfer", JOptionPane.YES_NO_OPTION );
if( optionPane == JOptionPane.YES_NO_OPTION )
{
output.writeObject( "PRESS 'SEND FILE' BUTTON" );
output.flush();
display.append( "\nWAITING FOR FILE" );
}
else
{
output.writeObject( "NO - Do not send file" );
output.flush();
display.append( "\nNO - Do not send file" );
}
}
} while ( !message.equals( "CLIENT>>> quit" ) );
// Close connection.
display.append( "\nUser terminated connection" );
enter.setEnabled( false );
output.close();
input.close();
connection.close();
++counter;
} // end while
} // end try
catch ( EOFException eof ) {
System.out.println( "Client terminated connection" );
}
catch ( IOException io ) {
io.printStackTrace();
}
} // end runServer
private void sendData( String s )
{
try {
output.writeObject( "SERVER>>> " + s );
output.flush();
display.append( "\nSERVER>>>" + s );
}
catch ( IOException cnfex ) {
display.append(
"\nError writing object" );
}
} // end sendData
public static void main( String args[] )
{
Server1 app = new Server1();
app.addWindowListener(
new WindowAdapter()
{
public void windowClosing( WindowEvent e )
{ System.exit( 0 );
}
}
);
app.runServer();
} // end main
} // end Server Class
- 9
- 10
- java.nio problemI had a NIO problem.
I tried to open a socket channel, and grep a HTML page from HTTP GET.
I did it success if I open and close socket channel everytime I send a
request and get the response.
However, if I keep open the socket channel and send multiple requests,
I'll get IOException.
Does anybody know how to solve this problem? Thanks in advance!
Note: I don't want to fire requests in parallel but one by one
sample code:
=============================================================
private Charset charset = Charset.forName("ISO-8859-1");
private SocketChannel channel;
try
{
// do connection
InetSocketAddress socketAddress =
new InetSocketAddress( "www.mydomain.com", 80);
channel = SocketChannel.open(socketAddress);
// send request #1
channel.write(charset.encode("GET /page1.html HTTP/1.0\r\n\r\n") );
// read response #1
ByteBuffer buffer = ByteBuffer.allocate(1024);
while ((channel.read(buffer)) != -1)
{
buffer.flip();
System.out.println(charset.decode(buffer));
buffer.clear();
}
// send request #2
channel.write(charset.encode("GET /page2.html HTTP/1.0\r\n\r\n") );
// read response #2
// program threw "java.io.IOException: Read failed" error
while ((channel.read(buffer)) != -1)
{
buffer.flip();
System.out.println(charset.decode(buffer));
buffer.clear();
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (channel != null)
{
try
{
channel.close();
} catch (IOException e) {}
}
}
=============================================================
- 11
- Is this syntactically valid Java?Is the following syntactically valid?
public class Foo {
public static void main(String[] args) {
for( foo: ; ; ); // Note statement label
}
}
javac is rejecting this, but IntelliJ is saying that it is valid. I
would appreciate a reference to the JLS if possible, so I can file a
bug report either with Sun or with JetBrains.
--
C. Benson Manica | I appreciate all corrections, polite or otherwise.
cbmanica(at)gmail.com |
----------------------| I do not currently read any posts posted through
sdf.lonestar.org | Google groups, due to rampant unchecked spam.
- 12
- java.lang.OutOfMemory ErrorI had used StringBuffer, as with 'out.println()' I will have to use +
operator for all the concatenation which I thought won't be that
efficient as using the StringBuffer.
- 13
- why call cipher.getInstance(),throw below error?my source code is:
Security.addProvider(new BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("RSA/NONE/PKCS1PADDING","BC");
when run it , cause below error,who can explain it,thanks in
advance.....
java.lang.ExceptionInInitializerError
at java.lang.Class.runStaticInitializers(Unknown Source)
at javax.crypto.Cipher.a(Unknown Source)
at javax.crypto.Cipher.getInstance(Unknown Source)
at
com.pioneer.bluray.security.authenticator.SignatureChecking.rsaDecrypt(Unknown
Source)
at
com.pioneer.bluray.security.authenticator.SignatureChecking.fetchSignature(Unknown
Source)
at
com.pioneer.bluray.security.authenticator.SignatureChecking.checkCredentialValues(Unknown
Source)
at
com.pioneer.bluray.security.authenticator.SignatureChecking.checkCredentials(Unknown
Source)
at
com.pioneer.bluray.security.authenticator.DVBSecUtils.invokeSecurity(Unknown
Source)
at org.dvb.lang.DVBClassLoader.securityCheck(Unknown Source)
at org.dvb.lang.DVBClassLoader.acquireData(Unknown Source)
at org.dvb.lang.DVBClassLoader.defineClassPrivileged(Unknown
Source)
at org.dvb.lang.DVBClassLoader.access$000(Unknown Source)
at org.dvb.lang.DVBClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Unknown Source)
at org.dvb.lang.DVBClassLoader.findClass(Unknown Source)
at org.dvb.lang.DVBClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.sun.tv.Request.execReq(Unknown Source)
at com.sun.tv.XletRunnable$ExecThread.run(Unknown Source)
at java.lang.Thread.startup(Unknown Source)
Caused by: java.lang.SecurityException: Cannot set up certs for
trusted CAs
at javax.crypto.SunJCE_b.<clinit>(Unknown Source)
... 20 more
Caused by: java.lang.SecurityException: Jurisdiction policy files
are not signed by trusted signers!
at javax.crypto.SunJCE_b.f(Unknown Source)
at javax.crypto.SunJCE_b.e(Unknown Source)
at javax.crypto.SunJCE_s.run(Unknown Source)
at java.security.AccessController.doPrivileged(Unknown Source)
at java.security.AccessController.doPrivileged(Unknown Source)
... 21 more
- 14
- Having issues with context listener and netbeansI'm new to netbeans and the whole JSP world in general (i have
experience in j2me and the j2se). I basically wanted to test out the
listener functions.
I get no errors with the following code, however, i'm also not able to
'break' where i want to be able to and I have no output as I would
expect. Any suggestions would be great.
MyHttpSessionListener.java
-------------------------------------------------------------
package com.maturitymodel;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class MyHttpSessionListener implements HttpSessionListener
{
public void sessionCreated(HttpSessionEvent e)
{
System.err.println("Hello new session");
}
public void sessionDestroyed(HttpSessionEvent e)
{
System.err.println("ByeBye old session");
}
}
---------------------------------------------------------------------------
web.xml
--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<listener>
<listener-class>com.maturitymodel.MyHttpSessionListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config><session-timeout>
30
</session-timeout></session-config><welcome-file-list><welcome-file>
index.jsp
</welcome-file></welcome-file-list></web-app>
-----------------------------------------------------------------------
index.jsp
------------------------------------------------------------------------
<%@ page session="true"%>
- 15
|
|
|