473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

About Applet....

539 Contributor
Is it possible to communicate the online database from my applet without any conditions? or limitations?

Conditions - a restricted combination of characters that might be suspected as a
pattern of a virus that should be blocked...Security concerns

Limitations- Not all characters in ascii are welcome in an online database...

It's just a weird idea...

Im currently experimenting a simple hashcode generator in an applet...(unique patterns)
Then i would like to save it in the database,

Is there any possibilities that might change the real code(generated code) as im transfering a copy of a hashcode to an online database?

Any reply would be greatly appreciated...

sukatoa.
Mar 7 '08 #1
10 1317
BigDaddyLH
1,216 Recognized Expert Top Contributor
Is it possible to communicate the online database from my applet without any conditions? or limitations?

Conditions - a restricted combination of characters that might be suspected as a
pattern of a virus that should be blocked...Security concerns

Limitations- Not all characters in ascii are welcome in an online database...

It's just a weird idea...

Im currently experimenting a simple hashcode generator in an applet...(unique patterns)
Then i would like to save it in the database,

Is there any possibilities that might change the real code(generated code) as im transfering a copy of a hashcode to an online database?

Any reply would be greatly appreciated...

sukatoa.
I'm not a big fan of applets, but the best practice is to write your application in three layers:

1. applet
2. Middle layer on server
3. Database

Your applet doesn't communicate directly with the database. Evidence is that no java.sql classes appear in the applet class, nor in any code that gets downloaded with the applet class.

Your applet communicates with a server component and that component communicates with the database.

You may want to reconsider using an applet and write this as a web application.
Mar 7 '08 #2
sukatoa
539 Contributor
I'm not a big fan of applets, but the best practice is to write your application in three layers:

1. applet
2. Middle layer on server
3. Database

Your applet doesn't communicate directly with the database. Evidence is that no java.sql classes appear in the applet class, nor in any code that gets downloaded with the applet class.

Your applet communicates with a server component and that component communicates with the database.

You may want to reconsider using an applet and write this as a web application.
Yah, i forgot to mension about the server...

so, can i assure that whatever combination of text i will be send to the server, it does not change the pattern until it saves on the database?

Sukatoa...
Mar 8 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
Yah, i forgot to mension about the server...

so, can i assure that whatever combination of text i will be send to the server, it does not change the pattern until it saves on the database?

Sukatoa...
Do you have something specific in mind when you ask this? I'm not sure what you are trying to say.
Mar 9 '08 #4
sukatoa
539 Contributor
Do you have something specific in mind when you ask this? I'm not sure what you are trying to say.
Im not pretty sure about the security exceptions in the cyberspace...

All i want is to generate a unique combination of characters and save it in a file for experiments....

Then after that, proceed to online database....

My question is, is the file i have generated would be stored 100% in the online database? Without changing its pattern?

For example, i have this,

*^($#7 )(*!@#@+___76544(new line transparent)
*&^%$!@%%$#()*& *&^%$

When i just open this in a textpad, the new line '\n' replaced with a rectangular box stands vertically....saved...

and when i open that file again from my applet, the pattern changed...

I get stucked in the middle of the experiment....

That was not so specific, but i think you can now understand this...

I will think again about this....

Thanks for the reply bigDaddy....
Mar 9 '08 #5
BigDaddyLH
1,216 Recognized Expert Top Contributor
Your questions keep shifting, but I believe your question now is: I can't seem to write "\n" to a file correctly. Is that correct? Post the code that is in error.
Mar 10 '08 #6
sukatoa
539 Contributor
Your questions keep shifting, but I believe your question now is: I can't seem to write "\n" to a file correctly. Is that correct? Post the code that is in error.
Expand|Select|Wrap|Line Numbers
  1. public void SaveFile(String path){
  2.         FileOutputStream writes = null;
  3.         String text = new String(textArea1.getText());
  4.         try{
  5.             byte out[] = text.getBytes();
  6.             writes = new FileOutputStream(path);
  7.             writes.write(out);
  8.         } catch(Exception e){
  9.             JOptionPane.showMessageDialog(null, "UNABLE TO SAVE FILE!!", "FATAL ERROR 98773", JOptionPane.WARNING_MESSAGE);
  10.         } finally{
  11.             try{
  12.                 if(!writes.equals(null)){ //Under tracing... But no problem...
  13.                     writes.close();
  14.                 }
  15.             } catch(Exception e){
  16.                 JOptionPane.showMessageDialog(null, "AN ERROR OCCURED WHILE CLOSING THE FILE!!", "FATAL ERROR 102", JOptionPane.WARNING_MESSAGE);
  17.             }
  18.         }
  19.     }
The code above has problem...
My source of text is the textArea... "Under experiment".....

After saving, try to view it in textpad... All newlines were replaced with rectangular box stands vertically... But when i open it again on my program, no problem... Maybe there is a difference of coding when it comes to newline...

The rectangular box that i mean is in 7F hex or FF hex in ASCII....

What can you suggest the way i write the text to file?

What is the weakness?....

Update me...
Mar 10 '08 #7
BigDaddyLH
1,216 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. public void SaveFile(String path){
  2.         FileOutputStream writes = null;
  3.         String text = new String(textArea1.getText());
  4.         try{
  5.             byte out[] = text.getBytes();
  6.             writes = new FileOutputStream(path);
  7.             writes.write(out);
  8.         } catch(Exception e){
  9.             JOptionPane.showMessageDialog(null, "UNABLE TO SAVE FILE!!", "FATAL ERROR 98773", JOptionPane.WARNING_MESSAGE);
  10.         } finally{
  11.             try{
  12.                 if(!writes.equals(null)){ //Under tracing... But no problem...
  13.                     writes.close();
  14.                 }
  15.             } catch(Exception e){
  16.                 JOptionPane.showMessageDialog(null, "AN ERROR OCCURED WHILE CLOSING THE FILE!!", "FATAL ERROR 102", JOptionPane.WARNING_MESSAGE);
  17.             }
  18.         }
  19.     }
The code above has problem...
My source of text is the textArea... "Under experiment".....

After saving, try to view it in textpad... All newlines were replaced with rectangular box stands vertically... But when i open it again on my program, no problem... Maybe there is a difference of coding when it comes to newline...

The rectangular box that i mean is in 7F hex or FF hex in ASCII....

What can you suggest the way i write the text to file?

What is the weakness?....

Update me...
There are several basic mistakes in your code. Here are the three biggest:
1. (Aside) Why are you making an unnecessary copy of a String? Your code:

Expand|Select|Wrap|Line Numbers
  1. String text = new String(textArea1.getText());
Can be written more simply as:

Expand|Select|Wrap|Line Numbers
  1. String text = textArea1.getText();
2. You need to understand the difference between text and binary data. You shouldn't be writing out a byte array using FileOutputStream. Take the tutorial on I/O:

http://java.sun.com/docs/books/tutor.../io/index.html

3. Text components like JTextArea already have a methods to simplify I/O: check the API for methods read and write:

http://java.sun.com/javase/6/docs/ap...a.lang.Object)
http://java.sun.com/javase/6/docs/ap...ava.io.Writer)

Demo:

Expand|Select|Wrap|Line Numbers
  1. public static void writeFromTextComponent(File file, JTextComponent comp) throws IOException {
  2.     FileWriter out = new FileWriter(file);
  3.     try {
  4.         comp.write(out);
  5.     } finally {
  6.         out.close();
  7.     }
  8. }
Mar 10 '08 #8
sukatoa
539 Contributor
There are several basic mistakes in your code. Here are the three biggest:
1. (Aside) Why are you making an unnecessary copy of a String? Your code:

Expand|Select|Wrap|Line Numbers
  1. String text = new String(textArea1.getText());
Can be written more simply as:

Expand|Select|Wrap|Line Numbers
  1. String text = textArea1.getText();
2. You need to understand the difference between text and binary data. You shouldn't be writing out a byte array using FileOutputStream. Take the tutorial on I/O:

http://java.sun.com/docs/books/tutor.../io/index.html

3. Text components like JTextArea already have a methods to simplify I/O: check the API for methods read and write:

http://java.sun.com/javase/6/docs/ap...a.lang.Object)
http://java.sun.com/javase/6/docs/ap...ava.io.Writer)

Demo:

Expand|Select|Wrap|Line Numbers
  1. public static void writeFromTextComponent(File file, JTextComponent comp) throws IOException {
  2.     FileWriter out = new FileWriter(file);
  3.     try {
  4.         comp.write(out);
  5.     } finally {
  6.         out.close();
  7.     }
  8. }
Roger....

About the string, don't worry, the JVM will change the byte code for it to optimize automatically....

And, it was not finalized... I forgot it.... sorry....

So, here is my new problem...

How safe is this code?

Expand|Select|Wrap|Line Numbers
  1. private void CopyFile(File source){
  2.         try{
  3.         FileWriter copy = new FileWriter(new File("TEMP.COM"));
  4.         FileReader view = new FileReader(source);
  5.         int node = 0;
  6.  
  7.         while((node = view.read()) != -1){
  8.             copy.write(node);
  9.         }
  10.         copy.close();
  11.         view.close();
  12.         }catch(Exception e){e.printStackTrace();} // for debugging
  13.     }
I've used it to transfer the .COM file to the original path....
Is this code has a quality enough?

Or you have the best idea how to implement it?
how is your algo if you know it BigDaddy?!!

Update me.... ;-)
Mar 10 '08 #9
BigDaddyLH
1,216 Recognized Expert Top Contributor
Roger....

About the string, don't worry, the JVM will change the byte code for it to optimize automatically....

And, it was not finalized... I forgot it.... sorry....

So, here is my new problem...

How safe is this code?

Expand|Select|Wrap|Line Numbers
  1. private void CopyFile(File source){
  2.         try{
  3.         FileWriter copy = new FileWriter(new File("TEMP.COM"));
  4.         FileReader view = new FileReader(source);
  5.         int node = 0;
  6.  
  7.         while((node = view.read()) != -1){
  8.             copy.write(node);
  9.         }
  10.         copy.close();
  11.         view.close();
  12.         }catch(Exception e){e.printStackTrace();} // for debugging
  13.     }
I've used it to transfer the .COM file to the original path....
Is this code has a quality enough?

Or you have the best idea how to implement it?
how is your algo if you know it BigDaddy?!!

Update me.... ;-)
1. If an exception is thrown, you don't close either stream.
2. When you are copying text files, it may make more sense to do a binary copy and not copy as text. The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.
Mar 10 '08 #10
sukatoa
539 Contributor
1. If an exception is thrown, you don't close either stream.
2. When you are copying text files, it may make more sense to do a binary copy and not copy as text. The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.
Expand|Select|Wrap|Line Numbers
  1. 1. If an exception is thrown, you don't close either stream.
I forgot again....

Expand|Select|Wrap|Line Numbers
  1. The exceptions to this include cases where you are chaning the charset encoding and when you are moving files between machines and are concerned about the difference in new-line characters between Windows and Linux, for example.
This is what i've been waiting for BigDaddy....
You got the best answer that would convence me to make changes in my codes....

Maybe we have misunderstandings in the previous posts....

I am aware of it....

Thanks.... ;-)
Mar 10 '08 #11

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

Similar topics

1
by: nathanlaan | last post by:
This is the stupidest thing I have ever seen. Java 1.2, 1.3, and 1.4.1, and 1.4.2 all define the Applet.getDocumentBase() method differently! How am I supposed to get the directory of the document...
2
by: Aljo_ | last post by:
Hello! I got a free evaluation copy of Borland's JBuilder9. I also got a book about JAVA, and I am trying to type, compile and run some examples from the book. The following - very simple -...
1
by: Charlie Kim | last post by:
Here is gnome applet source of mine. -------------------------------------------------- #!/usr/bin/env python import pydic import gtk import gnome.applet
1
by: Tormod Omholt-Jensen | last post by:
Ï need to dynamically insert an applet into a document. In IE 6.0 my code works fine, but there seems to be problems in Opera 7. The page looks like there is allocated space for an applet. ...
2
by: Roberto Gallo | last post by:
Hi; I have two problems regarding Scripts and Applets. I need to construct a page that has some instances of the same Applet. These instances are responsible to get informations from the user...
3
by: Larry Martin | last post by:
I am trying to run a Java Applet on my ascx page and am getting an IO exception when IE6 tries to load the applet. It seems a lot of others are getting the same problem but a search of the web did...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
0
by: ankur | last post by:
WHEN I RUN THIS WEB APPLICATION ON Tomcat5.5.9 SERVER MY HttpChatApplet sccessfully Loaded from ChatDispatch but running on some another PC HttpChatApplet not loaded my Coad ...
0
by: shanmukhi | last post by:
Hi All I got a problem in running java programs. i am not able to run java applet while running i got a problem as Loading Java Applet Failed java.lang.NoClassDefFoundError: App (wrong...
4
by: tudyfruity18 | last post by:
I'm suppose to write an applet that contains two buttons Investment calculator and Loan Calculator. When the Investment Calculator button is clicked, a frame appears in a new window for calculating...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.