public static String get_PostPageSourceByURLConnection(String urlRequestString,String PostParamString) { String WholeString = ""; try { URL url = new URL(urlRequestString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(PostParamString.getBytes().length)); connection.setUseCaches (false); DataOutputStream writer = new DataOutputStream(connection.getOutputStream ()); writer.writeBytes(PostParamString); writer.flush(); String line; StringBuffer strBuilder = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); while ((line = reader.readLine()) != null) { strBuilder = strBuilder.append(line); strBuilder = strBuilder.append("\n\n\n"); } WholeString = strBuilder.toString(); writer.close(); reader.close(); connection.disconnect(); } catch (Exception ex) { String s = ex.toString(); s = s.trim(); } finally { return WholeString; } }
Software Developer - Ahmedabad
Saturday, 15 December 2012
How to use HttpURLConnection POST data to web server?
Friday, 21 September 2012
Best HTML editor for Java Swing Application: EKIT
Ekit is a free open source Java HTML editor applet and application. The Ekit standalone also allows for HTML to be loaded and saved, as well as serialized and saved as an RTF. It is approaching its first production release version.
Ekit has proven to be very popular, with hundreds of developers using it in over 30 countries. Many have added to it already, and I always welcome additional contributions. Please feel free to share any enhancements or bug reports with Ekit
Download Ekit
Implementation:
import com.hexidec.ekit.EkitCore;
private EkitCore ekitCore;
Jscrollpanel.add(ekitCore.getToolBarMain(true));
Jscrollpanel.add(ekitCore.getToolBarFormat(true));
Jscrollpanel.add(ekitCore.getToolBarStyles(true));
Jscrollpanel.add(ekitCore);
It’s Simple.
CSV Splitter : Make Small Sized CSV files from Large CSV file
You can easily split huge CSV files in a mater of seconds.
Instructions:
1. Fill in necessary information:
CSV file: the path to the CSV that you wanted to split.
Number of lines: the maximum number of lines/rows in each splitted piece.
Max Pieces: limit the number of output files. ’0′ is unlimited.
CSV file: the path to the CSV that you wanted to split.
Number of lines: the maximum number of lines/rows in each splitted piece.
Max Pieces: limit the number of output files. ’0′ is unlimited.
2. Click “Split Now!”, and that’s it. You can find the splitted pieces in the a new folder of the same directory of the CSV file.
If you think this is helpful, just go and download CSV Splitter free of charge.
Java mail,how to set reply-to and sender name (From)
MimeMessage emailMessage = new MimeMessage();
you can set “sender Name” as below :
emailMessage.setFrom(new InternetAddress(from,senderName));
you can set “reply-to” as below :
emailMessage.setReplyTo(InternetAddress.parse(replytoemail));
How to delete row from jtable after sorting
We can handle this using co-ordination jtable view and table model
convertRowIndexToModel
convertRowIndexToView
convertRowIndexToView
probably will need something like this:
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
int modelRow = table.convertRowIndexToModel(viewRow);
table.getModel().removeRow(modelRow);
How can send email from a Java app using Gmail?
You need to Set Properties as Below :
String host = "smtp.gmail.com";
String from = "user name";//email address
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", "asdfgh");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
String from = "user name";//email address
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", "asdfgh");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
URLConnection with proxy authentication in java
Basic Proxy-Authorization is not longer working.
Use Authenticator for URLConnection with Proxy authentication.
Authenticator.setDefault(new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(proxyUsername,proxyPassword.toCharArray());
}
});
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(proxyUsername,proxyPassword.toCharArray());
}
});
Subscribe to:
Posts (Atom)