#
--sunfruit
其實解決辦法很簡單
首先保證進行了正確的數字簽名
然后使用java web start 發布application一定會有jnlp文件,關鍵就在這里
在jnlp文件里面添加
<security>
<all-permissions/>
</security>
這幾行就可以了,當用戶執行了app的時候,會彈出提示框提示用戶是否信任xxx證書,當用戶選擇信任以后就可以訪問本地系統了
--sunfruit
在使用java web start發布Application還有在網頁上面發布Applet的時候如果不進行數字簽名,那么會有安全級別的限制,并且在程序界面的最下面會有Application window 的字樣,很是不爽,只要是進行了數字簽名這些苦惱就沒有了,而且也可以訪問用戶的本地IO系統,下面就說一下如何進行數據簽名
其實簽名過程很簡單,JDK自身就有工具可以進行簽名,下面的過程中 xxxx 表示該內容是自定義的
第一部生成 keystore 文件
keytool -genkey -keystore xxxx.keystore -alias xxxx 例如[keytool -genkey -keystore sunfruit.keystore -alias sunfruit]
這個過程比較繁瑣,要填寫好幾項內容,比如生成的keystore文件為 sunfruit.keystore ,下面需要使用
第二步進行數據簽名,呵呵,快吧
jarsigner -keystore sunfruit.keystore xxxx.jar sunfruit
命令行中的xxxx.jar是要進行簽名的jar文件
第二步進行完畢以后,jar文件就已經簽名完畢了,可以使用,當然還有一些其他的功能,比如導出cer文件
keytool -export -keystore sunfruit.keystore -alias sunfruit -file sunfruit.cer
簡單吧,其實簽名--就是這么簡單
--sunfruit
用HttpURLConnection進行Post方式提交,下面給出一個例子
URL url = null;
HttpURLConnection httpurlconnection = null;
try
{
url = new URL("http://xxxx");
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setDoOutput(true);
httpurlconnection.setRequestMethod("POST");
String username="username=02000001";
httpurlconnection.getOutputStream().write(username.getBytes());
httpurlconnection.getOutputStream().flush();
httpurlconnection.getOutputStream().close();
int code = httpurlconnection.getResponseCode();
System.out.println("code " + code);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(httpurlconnection!=null)
httpurlconnection.disconnect();
}
其中HttpURLConnection中的addRequestProperty方法,并不是用來添加Parameter 的,而是用來設置請求的頭信息,比如:
setRequestProperty("Content-type","text/html");
setRequestProperty("Connection", "close");
setRequestProperty("Content-Length",xxx);
當然如果不設置的話,可以走默認值,上面的例子中就沒有進行相關設置,但是也可以正確執行

-----

-----

-----

-----

-----

-----

-----

-----

-----

-----

-----
--sunfruit
前一段時間寫了一個
[原創]JAVA中圖片上疊加文字的方法,本來這方面的例子在網絡上面很多,而且當時寫的時候也沒有遇到什么問題,所以也沒有什么感覺要注意的地方
昨天由于一些原因需要在一個已有的圖片上面畫點,然后再顯示出來,感覺上和
[原創]JAVA中圖片上疊加文字的方法很類似,也就沒當回事按照自己的思路就寫了,很容易想到讀取已存在的圖片內容然后生成
ImageIcon imageIcon=new ImageIcon(bytes); 對象然后生成
Image image=imageIcon.getImage(); 對象,這個時候只要是從image實例里面獲得Graphics對象就可以對圖片進行編輯了但是下面這步卻報錯了
Graphics g =image.getGraphics(); //這步抱錯:UnsupportedOperationException: getGraphics() not valid for images created with createImage(producer)
怎么調試都不行,于是google一把,發現遇到這個問題的人不少,解決辦法是不能從Image對象獲得Graphics,而是要從BufferedImage對象獲得Graphics,于是調整思路將代碼修改為
BufferedImage bufferedImage=new BufferedImage(imageIcon.getIconHeight(),imageIcon.getIconWidth(),BufferedImage.TYPE_INT_RGB);
Graphics2D g=(Graphics2D)bufferedImage.getGraphics();這次測試通過可以獲得Graphics對象了
這里說明一點:Graphics g =image.getGraphics(); 這一步如果是從Java的圖形組件里面獲得的Image對象,然后獲得Graphics對象就不會有問題
在已有的圖片上面畫圖的完整例子見:
[原創]JAVA在已有圖片上面畫圖的實例
--sunfruit
簡介:JAVA在已有圖片上面畫圖的實例,下面的程序在已有的圖片上面畫了一個藍色的方塊
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.util.Random;
import java.io.IOException;
import java.io.File;
public class ImageTest {
public ImageTest() throws Exception {
String ext="png";
FileInputStream in = new FileInputStream("已有圖片的路徑");
byte[] bytes = new byte[in.available()];
in.read(bytes);
in.close();
Random random=new Random(System.currentTimeMillis());
ImageIcon imageIcon = new ImageIcon(bytes);
BufferedImage bufferedImage=new BufferedImage(imageIcon.getIconHeight(),imageIcon.getIconWidth(),BufferedImage.TYPE_INT_RGB);
Graphics2D g=(Graphics2D)bufferedImage.getGraphics();
g.setColor(Color.blue);
g.drawRect(5,5,5,5);
g.fillRect(5,5,5,5);
g.drawImage(imageIcon.getImage(),0,0,imageIcon.getIconHeight(),imageIcon.getIconWidth(),imageIcon.getImageObserver());
String filepath = System.getProperty("java.io.tmpdir") + random.nextInt(99999) + "." + ext;
try {
ImageIO.write(bufferedImage, ext, new File(filepath));
System.out.println("文件已經生成,路經為" + filepath);
}
catch (IOException ex) {
ex.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
new ImageTest();
}
}
--sunfruit
《談談心,戀戀愛》,續《
愛,直至成傷》沒啥說的,下載地址
覺得好的要頂歐 : )
http://m.tkk7.com/Files/sunfruit/ttxlla.rar
--sunfruit
JDK:1.3.x以上
功能:下面是一個簡單在圖片上面疊加文字的方法,有朋友如果有這方面的問題,就起個了解的作用
代碼如下:
import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.Random;
/**
* <p>Title: 圖片疊加文字類</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author sunfruit
* @version 1.0
*/
public class ImageAddWord {
Random random=new Random(System.currentTimeMillis());
BufferedImage buffImage=null;
Graphics2D g=null;
public ImageAddWord(int width, int height) {
buffImage=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
}
public ImageAddWord()
{
this(32,32);
}
/**
* 圖片生成方法,如果需要在已有的圖片疊加文字,需要先調用g.drawImage方法將圖片繪制,再將文字繪制
* @param str String 文字內容
* @param ext String 文件后綴名 png或是jpg
*/
public void drawWord(String str,String ext)
{
g=buffImage.createGraphics();
/**
如果要在已有的圖片疊加文字,這里調用g.drawImage()該方法,繪制圖片,酌情去掉下面的方法
*/
g.setColor(Color.WHITE);//在已有的圖片疊加文字時 該方法酌情添加
g.fillRect(0, 0, buffImage.getWidth(), buffImage.getHeight());//在已有的圖片疊加文字時 該方法酌情添加
g.setColor(Color.BLACK);//設定文字顏色
g.drawString(str,0,12);
String filepath=System.getProperty("java.io.tmpdir") +random.nextInt(99999)+"." + ext;
try {
ImageIO.write(buffImage, ext,
new File(filepath));
System.out.println("文件已經生成,路經為"+filepath);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void setFont(Font font)
{
g.setFont(font);
}
public static void main(String[] args) {
ImageAddWord imageAddWord=new ImageAddWord(132,16);
String str="A B C";
imageAddWord.drawWord(str,"png");
}
}
--sunfruit
??? 用JAVA編寫的桌面程序啟動的預顯窗口實例
??? 簡介:
????????程序啟動會預先顯示一個預顯窗口,主程序啟動完畢后預顯窗口關閉
??? 歡迎大家提意見,交流
?? 下載地址
??? 說明:apprun.jar可以直接運行 src中是源代碼
??? http://m.tkk7.com/Files/sunfruit/apprunmodel.rar
--sunfruit
開發web相關程序的時候總是要遇到限制用戶不能使用同一個帳號同時多次登錄的問題,我從三個方向對這樣的問題做了監控
1,用戶登錄以后點擊注銷推出
2,用戶點擊IE的 X 關閉里IE窗口
3,用戶的session過期
只要是監控了以上三點,就能滿足絕大部分的要求,以上是一個思路,有一個缺陷,就是如果客戶機突然斷電,那么只有session過期了以后才能登錄,這個地方是一個缺陷。
下面給出具體的實現代碼,如果大家有更好的辦法,歡迎交流,共同進步
http://sunfruit.bokee.com/inc/session.rar
附件說明 :
1.工程使用JB做的,使用了log4j,log4j的包在工程的WEB-INF的LIB文件夾內,取出后重新引用。
2.可以直接發布war包,直接可以測試