Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 3:08 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: posting from java to html
PostPosted: Tue Jan 19, 2010 4:29 pm 
Offline
Newbie
User avatar

Joined: Tue Jan 19, 2010 4:06 pm
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

Hello,

I need something that press the button on HTML from java,
from researches I got "Posting"
I post from C# and it works, but in java I couldnt get to the next page with posting methods.

can I solve this problem.

on the fist page there is user name and password, and apply button.
from java I want to press the button with given (in java) parameters and get the html code of the next page.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: posting from java to html
PostPosted: Wed Jan 27, 2010 11:33 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
This html Java editor code , it should be helpful to you .

Code:

import java
.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.undo.*;
import java.util.*;
import java.net.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;


/**
 * Simple HTML 'editor'
 * @author sjalle
 * @version 1.0
 */

public class HTMLEditor extends JFrame implements ActionListenerDocumentListenerUndoableEditListener {
  
BorderLayout borderLayout1 = new BorderLayout();
  
JPanel jPanel1 = new JPanel();
  
JButton getFileBtn = new JButton();
  
JButton closeBtn = new JButton();
  
JTabbedPane jTabbedPane1 = new JTabbedPane();
  
JScrollPane jScrollPane1 = new JScrollPane();
  
JScrollPane jScrollPane2 = new JScrollPane();
  
JEditorPane edText = new JEditorPane();
  
JEditorPane edHTML = new JEditorPane();
  
Document textDoc=null;
  
ArrayList undoList=new ArrayList();
  
JButton undoBtn = new JButton();

  public 
HTMLEditor() {
    try {
      
jbInit();
      
getFileBtn.addActionListener(this);
      
undoBtn.addActionListener(this);
      
closeBtn.addActionListener(this);
    }
    catch(
Exception e) {
      
e.printStackTrace();
    }
  }
  public 
void loadFile(String fpthrows Exception {

    if (
fp==null) return;
    
String filePath=fp;
    
File f=new File(fp);
    
long av=f.length();
    if (
av==0) {
      
System.out.println("no data");
      return;
    }
    
URL url=new URL("file:"+fp);
    
edHTML.setPage(url);
    
FileReader fr=new FileReader(f);
    
edText.read(fr,null);

    
textDoc=this.edText.getDocument();
    
textDoc.addDocumentListener(this);
    
textDoc.addUndoableEditListener(this);

    
this.validate();
  }

  public static 
void main(String[] args) {
    
HTMLEditor ed = new HTMLEditor();
    
ed.setBounds(20,20,500,400);
    
ed.setVisible(true);
  }
  private 
void jbInit() throws Exception {
    
this.getContentPane().setLayout(borderLayout1);
    
getFileBtn.setText("Get FIle");
    
closeBtn.setText("Close");
    
edText.setText("jEditorPane1");
    
edHTML.setEditable(false);
    
edHTML.setText("jEditorPane2");
    
undoBtn.setEnabled(false);
    
undoBtn.setText("Undo");
    
this.getContentPane().add(jPanel1BorderLayout.SOUTH);
    
jPanel1.add(getFileBtnnull);
    
jPanel1.add(undoBtnnull);
    
jPanel1.add(closeBtnnull);
    
this.getContentPane().add(jTabbedPane1BorderLayout.CENTER);
    
jTabbedPane1.add(jScrollPane1,   "HTML");
    
jScrollPane1.getViewport().add(edHTMLnull);
    
jTabbedPane1.add(jScrollPane2,   "Text");
    
jScrollPane2.getViewport().add(edTextnull);
    
addWindowListener(new WindowAdapter() {
      public 
void windowClosing(WindowEvent e) {
        
System.exit(0);
      }
    });
  }
  public 
void actionPerformed(ActionEvent e) {
    if (
e.getSource() == this.closeBtn)
      
System.exit(0);
    if (
e.getSource() == this.getFileBtn) {
      
FileDialog fd=new FileDialog(this,"Select File",FileDialog.LOAD);
      
fd.setVisible(true);
      
String fName=fd.getFile();
      if (
fName==null) return;
      
String fPath=fd.getDirectory()+fName;
      try {
        
loadFile(fPath);
      }
      catch (
Exception ex) {
        
System.out.println(ex.getMessage());
        
ex.printStackTrace();
      }
    } else if (
e.getSource() == this.undoBtn) {
      
undoLast();
    }
  }
  public 
void undoLast() {
    
int ix=undoList.size()-1;
    if (
ix>=0) {
      
UndoableEdit ue=(UndoableEdit)this.undoList.get(ix);
      
ue.undo();;
      
undoList.remove(ix);
      if (
undoList.size()==0this.undoBtn.setEnabled(false);
    }
  }
  
/**
   * If the undoList has any elements then the document has
   * been changed
   * @return
   */
  
public boolean isFileChanged() {
    return 
this.undoList.size()>0;
  }
  public 
void insertUpdate(DocumentEvent e) {
    
System.out.println("insertUpdate");
  }
  public 
void removeUpdate(DocumentEvent e) {
    
System.out.println("removeUpdate");
  }
  public 
void changedUpdate(DocumentEvent e) {
    
System.out.println("changedUpdate");
  }
  public 
void undoableEditHappened(UndoableEditEvent e) {
    
this.undoList.add(e.getEdit());
    
this.undoBtn.setEnabled(true);
  }
}
 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Java seminar topic with demo  Java  Anonymous  1
 java project code  Java  Anonymous  0
 change Font of text in java  Java examples  msi_333  1
 Configuring the header html font  HTML examples  msi_333  0
 multi-frameset and non-re-sizable html frame pages  HTML examples  msi_333  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team