jaka.ramdani -1 Newbie Poster

Maybe because the file path separator you used not consistent:

File savedFile = new File("C:/apache-tomcat-6.0.16/webapps/example/"+"images\\"+finalimage);

if you using Windows, change your file path separator to '\\' instead of '/':

File savedFile = new File("C:\\apache-tomcat-6.0.16\\webapps\\example\\"+"images\\"+finalimage);
jaka.ramdani -1 Newbie Poster

I don't think method type matter (GET or POST) in this case, in case of form submission you better use onSubmit action rather than onClick. CMIIW.

jaka.ramdani -1 Newbie Poster
jaka.ramdani -1 Newbie Poster

You could try this code:

<%-- 
    Document   : index
    Created on : Jul 27, 2010, 2:09:50 PM
    Author     : jaka
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.File" %>
<%@page import="java.io.FileFilter" %>
<%@page import="java.io.IOException" %>
<%
String currDirStr = getServletContext().getRealPath("");
File[] folders = null;
try {
    File currDir = new File(currDirStr);
    if(currDir.exists()) {
        folders = currDir.listFiles(new FileFilter() {

            public boolean accept(File pathname) {
                String name = pathname.getName();
                if(pathname.isDirectory()) {
                    if("WEB-INF".equals(name) || "META-INF".equals(name)) {
                        return false;
                    }
                    return true;
                }
                return false;
            }
        });
        if(folders == null) {
            folders = new File[0];
        }
    }
} catch(Exception ex) {}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">



<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form method="GET">
            <table border="1">
                <tbody>
                    <tr>
                        <td>Select Folder:</td>
                        <td>
                            <select name="folder">
                                <%
                                for(File folder : folders) { %>
                                <option value="<%= folder.getAbsolutePath() %>"><%= folder.getName() %></option>
                                <% } %>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <input type="submit" value="Submit" />
                        </td>
                    </tr>
                </tbody>
            </table>

        </form>
    </body>
</html>
jaka.ramdani -1 Newbie Poster

You can use Observer-Pattern, i made a quite simple sample which will printing current datetime to console and within relatively same time append same current datetime to an JTextArea, scheduled every 5 seconds, infinitely (till program closed).

/*
 * MyFrame.java
 *
 * Created on Jan 7, 2010, 10:40:13 AM
 */
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author jaka
 */
public class MyFrame extends javax.swing.JFrame implements Observer {

    /** Creates new form MyFrame */
    public MyFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        outputArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText(org.openide.util.NbBundle.getMessage(MyFrame.class, "MyFrame.jLabel1.text")); // NOI18N

        outputArea.setColumns(20);
        outputArea.setRows(5);
        jScrollPane1.setViewportView(outputArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    public void update(Observable o, Object obj) {
        String text = (String) obj;
        outputArea.append(text);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MyFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea outputArea;
    // End of variables declaration


}

and the Main.java

import java.util.Calendar;
import java.util.Date;
import …
jaka.ramdani -1 Newbie Poster

as far as i know, mysql driver class is "mysql.jdbc.Driver" without "root" as in your code,
and you don't have to call newInstance() method,
try to change your code like this:

public class Test {
  public static void main(String[] args) {
    try {
      Class.forName("mysql.jdbc.Driver");
      System.out.println("Good to go");
    } catch (Exception E) {
      System.out.println("JDBC Driver error");  
    }
  }
}

regards,

jaka.ramdani -1 Newbie Poster

Hi all I need to read an Excel sheet using java and I need to know how many columns are there in that excel sheet. Please drop a code snippet to this thread

Try using JXL. Below some simple approach for getting total rows and columns of a Worksheet in an Excel file.

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 *
 * @author jaka
 */
public class Jxl1 {

    public static void main(String args[]) {
        try {
            File excelFile = new File("C:\\sample-file.xls");
            Workbook wb = Workbook.getWorkbook(excelFile);
            Sheet sheet = wb.getSheet(1);
            int column = sheet.getColumns();
            int row = sheet.getRows();

            System.out.println("Total Columns: " + column);
            System.out.println("Total Rows: " + row);
        } catch (IOException ex) {
            Logger.getLogger(Jxl1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BiffException ex) {
            Logger.getLogger(Jxl1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

hope will help ..

-jaka

verruckt24 commented: For providing code, when she has already been warned against it -1
jaka.ramdani -1 Newbie Poster

Oh, i see ..
I think you can't access file in linux from windows just using java.io.File cause it is in another layer (network).

try open the path:

\\10.123.45.67\apps\user\staging\aa\log\success.log

using Windows Explorer, i guess it will cause same error:
"network does not found"

unless you're accessing samba path for your linux file, it can't be accessed by your code.

jaka.ramdani -1 Newbie Poster

Thanks a lot for the replies!
I have just looked up some i18n (internationalization) tutorials. It is pretty much what i am looking for. I wasn't sure what to use to implement the language feature. That's where i needed the assistance.
We are constructing a desktop application btw :D

If i have anymore issues, i will re-post. Thanks again!

have you consider using Swing Application Framework, this framework already manage internationalization. They use resource bundle (properties file) for the swing component (text, color, font, etc).

Use Netbeans 6 for simple approach, it is already using Swing Application Framework for its default Desktop Application Project, just study the sample code.

Hope will help.
-jaka

jaka.ramdani -1 Newbie Poster

it just a matter of escape character '\' in windows,
you need to type '\\' for single backslash '\', and for double backslash you'll need '\\\\', so instead of

file = new File("\\10.123.45.67\apps\user\staging\aa\log\success.*");

you must use:

file = new File("\\\\10.123.45.67\\apps\\user\\staging\\aa\\log\\success.log");

don't use success.* cause Java will not understand that, you must specify full name with its extension.

CMIIW,

jaka.ramdani -1 Newbie Poster

You may want to change your code like this:

import javax.swing.*;

import java.awt.*;


public   class keyboard {
		
  public static void main(String args[]) {
    String s[] = {"esc","F1","F2","F3","F4","F5",
                    "F6","F7","F8","F9","F10","F11","F12",
                    "psc","slk","pau"
    };
      
      
    JButton j[] =  new JButton[s.length];   
    
    for(int i=0; i < s.length; i++) {
      //initialise buttons
      j[i] = new JButton(s[i]);
      //j[i].setText(s[i]);
    }
   
    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
          
    for(int i = 0; i < s.length; i++) {
      f.add(j[i]);
    }
  
    f.pack();
      
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }
	
}

you got NullPointerException in your code because you haven't initialize button in your array.

JButton j[] =  new JButton[s.length];   

     //all button in above array is still null     
     for(int i=0;i<s.length;i++)
         j[i].setText(s[i]);

hope will help ..

jaka.ramdani -1 Newbie Poster

send me code which finds sytem information in java

try using this:

import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;


public class Foo {

    public static void main(String args[]) {
        Properties systemProps = System.getProperties();
        Set<Entry<Object, Object>> sets = systemProps.entrySet();
        System.out.println("systems properties:");
        for(Entry<Object,Object> entry : sets) {
            System.out.println("name: " + entry.getKey() + ", value: " + entry.getValue());
        }
    }
}

in my system, it will print something like these (no masking since i don't think it will endangered me, lol):

systems properties:
name: java.runtime.name, value: Java(TM) SE Runtime Environment
name: sun.boot.library.path, value: C:\DevTools\jdk1.6.0_05\jre\bin
name: java.vm.version, value: 10.0-b19
name: java.vm.vendor, value: Sun Microsystems Inc.
name: java.vendor.url, value: http://java.sun.com/
name: path.separator, value: ;
name: java.vm.name, value: Java HotSpot(TM) Client VM
name: file.encoding.pkg, value: sun.io
name: sun.java.launcher, value: SUN_STANDARD
name: user.country, value: ID
name: sun.os.patch.level, value: Service Pack 2
name: java.vm.specification.name, value: Java Virtual Machine Specification
name: user.dir, value: C:\Projects\personal\manga-downloader
name: java.runtime.version, value: 1.6.0_05-b13
name: java.awt.graphicsenv, value: sun.awt.Win32GraphicsEnvironment
name: java.endorsed.dirs, value: C:\DevTools\jdk1.6.0_05\jre\lib\endorsed
name: os.arch, value: x86
name: java.io.tmpdir, value: C:\DOCUME~1\jaka\LOCALS~1\Temp\
name: line.separator, value: 

name: java.vm.specification.vendor, value: Sun Microsystems Inc.
name: user.variant, value: 
name: os.name, value: Windows XP
name: sun.jnu.encoding, value: Cp1252
name: java.library.path, value: C:\DevTools\jdk1.6.0_05\jre\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\DevTools\jdk1.6.0_05\bin;c:\DevTools\OpenSSL\bin\
name: java.specification.name, value: Java Platform API Specification
name: java.class.version, value: 50.0
name: sun.management.compiler, value: HotSpot Client Compiler
name: os.version, value: 5.1
name: user.home, value: C:\Documents and Settings\jaka
name: user.timezone, value: 
name: java.awt.printerjob, value: sun.awt.windows.WPrinterJob
name: file.encoding, value: Cp1252
name: java.specification.version, value: 1.6
name: java.class.path, value: C:\Projects\personal\manga-downloader\lib\htmlcleaner2_0.jar;C:\Projects\personal\manga-downloader\lib\htmlparser.jar;C:\Projects\personal\manga-downloader\lib\js.jar;C:\Projects\personal\manga-downloader\lib\slf4j-api-1.4.3.jar;C:\Projects\personal\manga-downloader\lib\slf4j-simple-1.4.3.jar;C:\Projects\personal\manga-downloader\lib\derbyclient.jar;C:\Projects\personal\manga-downloader\lib\dom4j-1.6.1.jar;C:\Projects\personal\manga-downloader\lib\jaxen-1.1-beta-7.jar;C:\Projects\personal\manga-downloader\lib\jdbc-x.jar;C:\Projects\personal\manga-downloader\lib\log4j-1.2.14.jar;C:\Projects\personal\manga-downloader\lib\slf4j-api-1.5.2.jar;C:\Projects\personal\manga-downloader\lib\slf4j-log4j12-1.5.2.jar;C:\Projects\personal\manga-downloader\build\classes
name: user.name, value: jaka
name: java.vm.specification.version, value: 1.0
name: java.home, value: …
jaka.ramdani -1 Newbie Poster

oh my fault i didnt make all the changes it does compile, rep for you!

glad it helps .. thanks for the rep.

jaka.ramdani -1 Newbie Poster

i got the recursion working, couldnt quite implent the new for loop, moved on to the next step, ei. trying to compare files in two ArrayLists, and the first hiccup is as follows:

ArrayList arrayList = new ArrayList();
            ArrayList arrayListAgain = new ArrayList();
            
            File[] files= f.listFiles();    
            for(int index = 0; index < files.length; index++)
            
            if (files[index].isFile())
            {
                 
                System.out.println ("here we are---"+files[index].getName());
               
                arrayList.add(files[index]);
                arrayListAgain.add(files[index]);
                
                if (arrayList(files[index]).length() == arrayListAgain(files[index]).length() && arrayList(files[index]).hashCode() != arrayListAgain(files[index]).hashCode())
                {
                    //do something;
                }
            }

Hmm my compiler friend tells me cannot find symbol - method arrayList(Java.io.File)??

The java class library for ArrayList was not helpful to me.

maybe you mean something like this?

ArrayList<File> arrayList = new ArrayList<File>();
    ArrayList<File> arrayListAgain = new ArrayList<File>();
    
    File[] files= f.listFiles();    
    for(int index = 0; index < files.length; index++)
    
    if (files[index].isFile())
    {
         
        System.out.println ("here we are---" + files[index].getName());
       
        arrayList.add(files[index]);
        arrayListAgain.add(files[index]);
        
        if (arrayList.get(index).length() == arrayListAgain.get(index).length() && 
          arrayList.get(index).hashCode() != arrayListAgain.get(index).hashCode())
        {
            //do something;
        }
    }
jaka.ramdani -1 Newbie Poster

hi , actully i have read filters in servlet.
but i didnt understand , the actual working of filters ( in practicle environment).
i want to know that , when i am sending request to server and i am using filter before request went to server. so that process is happening on server side or client side ?

and i want to send password in encrypted format from html page to servlet how to do this ?
please if any one have any idea please response ( Atleast tell the process how to proceed).

filter always run in server env.

here's the way to send your encrypted password to server
1. add one hidden field in your login form i.e with name hashed_pass, and assume your password filed named pass
2. add onSubmit action in your form which will do these:
- hash your inputted plain password (try lo look some md5 hash javascript, there's a lot out of there)
- change you hashed_pass field value to hashed value of your inputted password
- set your password field to empty since you don't want plain value of your password is submitted
- submit the form
- authenticate using the hashed password
3. done

it may like these, except i don't provide the md5 javascript code, and assume the method to perform md5 hash is md5()

function hashOnSubmit(theForm) {
   var passwd_field = theForm.pass;
   var hashedpasswd_field = theForm.hashed_pass;
   var …
jaka.ramdani -1 Newbie Poster

i am new in java can any one please tell me the main use of constructor
if we can use method
in what cases its necessary to use constuctor

just give it a simple though, there is Object in Java, and the Object has Method which is its accessor. SO you cannot access the Object accessor before the Object itself is created (initialized) isn't it, except the method is static (which don't necessarily the Object to be instantiated), and one way to create/instantiate an Object is to call it constructor, jvm will give empty constructor for your classess even if you don't provide one.

hope it will give you some light.

regards,

jaka.ramdani -1 Newbie Poster

Just guessing, coz you don't provide the line where the error occured.
Try delete the

throw new UnsupportedOperationException("Not yet implemented");

from your

accessDBinit

method.

Tell me if it's working.
Just suggestion, why don't you use

PreparedStatement

instead of

Statement

for cleaner code, and try-finally block when you dealing with open-close database connection ..