| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
25 | 26 | 27 | 28 | 29 | 30 | 31 | |||
1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
8 | 9 | 10 | 11 | 12 | 13 | 14 | |||
15 | 16 | 17 | 18 | 19 | 20 | 21 | |||
22 | 23 | 24 | 25 | 26 | 27 | 28 | |||
29 | 30 | 1 | 2 | 3 | 4 | 5 |
引用
蔣委員長 的 如何將class打包exe文件
class文件打包exe文件要經(jīng)過兩個步驟:
第一步:將class文件打包成jar文件,請參見我的上一篇文章:http://maidini.blog.163.com/blog/static/37762704200848910573/
第二步:將jar文件打包成exe文件。這是今天的重點
將jar打包exe 有許多工具,我以exe4j為例詳解打包過程:
第一步:下載exe4j,最新版本為4.1 如下圖 exe4j的官方網(wǎng)站
第二步:運行exe4j.exe 我使用的是免安裝版(zip) 如下圖
第三步:運行軟件exe4j,然后點擊Next
第四步:選擇第二項"JAR in EXE mode",然后點擊Next
第五步:在General中填入名稱,在Directories填入生成exe的目錄位置。如下圖:我將生成exe目錄設(shè)置為C:\ok ,然后點Next
第六步:Executable name處填入生成exe文件的名稱,Icon File處填寫圖標(biāo)文件位置,再點Next
第七步:首先設(shè)置Class Path的位置,即jar文件的位置。然后點OK
第八步:接著設(shè)置Main-Class 的位置,即main方法所在的位置。然后點OK 如下圖
設(shè)置完成后,如下圖: 一定要先設(shè)置Class Path,再設(shè)置Main class
第九步:填寫版本號,最好不要填寫第二項。否則可能造成錯誤(見后面),最后點擊Finish即可
錯誤內(nèi)容:No JVM could be found on your system. Please define EXE4J_JAVA_HOME to point to an installed JDK or JRE or download a JRE from www.java.com
當(dāng)時出現(xiàn)這個錯誤,查看了JDK和JRE都沒有問題,exe4j也是最新版。后來才發(fā)現(xiàn)是設(shè)置"Maximum version"。如果不填寫"Maximum version",就不報錯。也不知道是不是exe4j的BUG
第十步:完成所有設(shè)置,點擊“Click Here to Start the Application”可以運行測試生成的EXE文件
生成的最終的EXE程序,雙擊直接運行?,F(xiàn)在可以把自己寫的小程序發(fā)給朋友們玩玩啦,呵呵
引用
蔣委員長 的 如何將Class打包Jar文件--Eclipse
開發(fā)環(huán)境:Eclipse + Win XP SP2
使用插件:Fatjar、Jigloo
閑話少說,直接切入正題。首先打開Eclipse,創(chuàng)建一個Java工程。如下圖:我機(jī)子上的是JDK1.6
第二步:用Jigloo插件創(chuàng)建一個窗體,為了更明顯演示我將窗體名字修改為“這是一個測試程序”。如下圖:
第三步:現(xiàn)在就該將運行正常的java程序打包成jar文件。我使用Fatjar插件打包相當(dāng)方便、傻瓜。直接右鍵選擇要打包的工程,彈出的菜單中選擇“Build Fat Jar”。如下圖:
第四步:彈出對話框,需要將引導(dǎo)路徑修改,其他選項使用默認(rèn)設(shè)置,然后點擊Finish。“Main-Class”這項修改為Main方法所在的文件。此步不可缺少,否則打包的Jar文件雙擊不可運行。
稍等一下,就打包成功如下圖:出現(xiàn)一個testexe_fat.jar文件。
進(jìn)入工程所在的目錄也可以看到一個testexe_fat.jar文件,雙擊它,就運行了。如果無誤應(yīng)該彈出像圖2的界面。如下圖:
選擇jar文件右鍵,點擊open。相當(dāng)于雙擊jar文件如下圖:
總結(jié):打包Jar文件是將分散Class文件統(tǒng)一封裝的好辦法。雙擊運行速度與沒打包前運行速度沒有區(qū)別。打包一定要設(shè)置好Main-Class的路徑,否則JVM找不到入口程序。
如果不知道如何在Eclipse中安裝插件,請參見我的另一篇文章:http://maidini.blog.163.com/blog/static/37762704200832671334860/
引用
蔣委員長 的 Eclipse的插件安裝
眾所周知,Eclipse無法方便快速的開發(fā)Swing程序。因為Eclipse沒有自帶圖形化編碼窗口,如果要開發(fā)圖形化程序,只有手動敲代碼非常不方便?,F(xiàn)在有一個插件Jigloo提供圖形化程序開發(fā)窗口,可以即拖即顯。如何將它安裝到Eclipse當(dāng)中呢?
安裝插件一般使用Link方式:Link意味鏈接,Eclipse加載時通過鏈接找到安裝的插件
如上圖所示:我的Eclipse路徑C:\Program Files\Eclipse 然后將Jigloo解壓到Eclipse安裝目錄中。這里需要注意Jigloo目錄下必須要有個叫Eclipse的目錄,Eclipse的目錄下才是放入features和plugins目錄。以上圖為例:C:\Program Files\Eclipse\Jigloo\Eclipse 路徑里放入features和plugins目錄,即features目錄路徑為:C:\Program Files\Eclipse\Jigloo\Eclipse\features,plugins目錄路徑為:C:\Program Files\Eclipse\Jigloo\Eclipse\plugins 這里必須要強(qiáng)調(diào)目錄路徑,因為我使用的是Link方式安裝插件。插件安裝位置正確后,就該鏈接了(Link)。在Eclipse路徑C:\Program Files\Eclipse下建立一個links目錄(必須這個名字),并在links目錄下建立一個Jigloo.link的文件(文件名必須同插件目錄名相同,后綴名必須是link)。最后用記事本打開Jigloo.link文件,填入path = Jigloo(path = 插件目錄名)。保存后,重新啟動Eclipse。如下圖
在新建項目中出現(xiàn)了一個叫GUI Forms的項目,說明插件安裝成功,這就是Jigloo插件提供的圖形化開發(fā)工具。寫在最后:
向大家推薦一個插件Aptana,這個插件可以調(diào)試Javascript代碼和HTML代碼。此插件還是第一款支持ajax調(diào)試的程序。詳見http://www.aptana.com/ 插件下載地址http://update.aptana.com/install/studio/3.2/
因為新版本要收費(只有一個月免費試用),我使用的老版本,安裝到Eclipse中有3個按鈕(如上圖,黃色驚嘆號和紅色叉)
如題,廢話不多說。
JSP頁面
hello.jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>AJAX提交頁面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
function doso(){
var url = "actAction.do";
var s="武曉強(qiáng)斯蒂芬34-*(&_(*!$^_*!&#!^$+!*#&&";
s=encodeURIComponent(s); //轉(zhuǎn)換特殊字符
var parameter ="name="+s+"&email=abc@abc.com&www=http://wxq594808632.blog.163.com/";
var method = "POST";
function callBack(text){ //回調(diào)函數(shù)
alert("調(diào)用成功!\n名字為:"+text);
}
new Ajax().ajaxRequest(url,parameter,method,callBack); //調(diào)用方法發(fā)送Request
}
</script>
</head>
<body>
<input type="button" value="提交" onclick="doso()"/>
</body>
</html>
java類
ActAction.java
package ajaxpost;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.io.PrintWriter;
public class ActAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
//設(shè)置字符編碼返回的編碼
response.setContentType("text/html;charset=UTF-8");
//接收字符的編碼
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException ex) {
ex.printStackTrace();
}
String name = request.getParameter("name");
String email = request.getParameter("email");
String www = request.getParameter("www");
System.out.println(email);
System.out.println(name);
System.out.println(www);
// out.print(name+"\n"+email+"\n"+www);
out.print(name); //返回值
return null;
}
}
最重要滴
ajax.js
我用別人的。感謝這位大哥。。
/*
author zhangshuling
email zhangshuling1214@126.com
*/
function Ajax(){
var _xmlHttp = null;
this.createXMLHttpRequest = function(){
try{
if (window.ActiveXObject) {
_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
_xmlHttp = new XMLHttpRequest();
}
}catch(e){
alert(e.name +" : " + e.message);
}
}
this.backFunction = function(_backFunction){
if(_xmlHttp.readyState == 4) {
if(_xmlHttp.status == 200) {
_backFunction(_xmlHttp.responseText);//這里可以設(shè)置返回類型
}
}
_xmlHttp.onreadystatechange = null;
}
this.doPost = function(_url,_parameter,_backFunction){
try{
_xmlHttp.open("POST",_url, false);
_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
_xmlHttp.send(_parameter);
}catch(e){
alert(e.name +" : " + e.message);
}
}
this.doGet = function(_url,_parameter,_backFunction){
try{
var _random = Math.round(Math.random()*10000);
_xmlHttp.open("GET", (_url+"?random=" +_random +"&" + _parameter), false);
_xmlHttp.send(null);
}catch(e){
alert(e.name +" : " + e.message);
}
}
this.ajaxRequest = function(_url,_parameter,_method,_backFunction){
try{
this.createXMLHttpRequest();
if(_method.toLowerCase() == "post"){
this.doPost(_url,_parameter,_backFunction);
}else{
this.doGet(_url,_parameter,_backFunction);
}
try{
_xmlHttp.onreadystatechange = this.backFunction(_backFunction);
}catch(err){
//??????IE?????????????????
}
}catch(e){
alert(e.name +" : " + e.message);
}
}
}
/*
var url = "ajax.do";
var parameter = "parameter=parameter";
var method = "post"
function callBack(text){
....
}
new Ajax().ajaxRequest(url,parameter,method,callBack);
*/
經(jīng)過本人FF,IE6,IE7,測試。完全好用
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.io.BufferedInputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.File;
import javax.imageio.ImageIO;
public class Img2 {
//讀取遠(yuǎn)程url圖片,得到寬高
public int[] returnImgWH(String imgurl) {
boolean b=false;
try {
//實例化url
URL url = new URL(imgurl);
//載入圖片到輸入流
java.io.BufferedInputStream bis = new BufferedInputStream(url.openStream());
//實例化存儲字節(jié)數(shù)組
byte[] bytes = new byte[100];
//設(shè)置寫入路徑以及圖片名稱
OutputStream bos = new FileOutputStream(new File( "C:\\thetempimg.gif"));
int len;
while ((len = bis.read(bytes)) > 0) {
bos.write(bytes, 0, len);
}
bis.close();
bos.flush();
bos.close();
//關(guān)閉輸出流
b=true;
} catch (Exception e) {
//如果圖片未找到
b=false;
}
int[] a = new int[2];
if(b){ //圖片存在
//得到文件
java.io.File file = new java.io.File("C:\\thetempimg.gif");
BufferedImage bi = null;
try {
//讀取圖片
bi = javax.imageio.ImageIO.read(file);
} catch (IOException ex) {
ex.printStackTrace();
}
a[0] = bi.getWidth(); //獲得 寬度
a[1] = bi.getHeight(); //獲得 高度
//刪除文件
file.delete();
}else{ //圖片不存在
a=null;
}
return a;
}
public static void main(String[] args) {
Img2 i = new Img2();
int[] a=i.returnImgWH(" if(a==null){
System.out.println("圖片未找到!");
}else{
System.out.println("寬為" + a[0]);
System.out.println("高為" + a[1]);
}
}
}
如題
默認(rèn)排序方式為asc,可省略...
select * from table order by t1 desc, t2 desc , t3 desc;
function jsTrim(value)
{
var reg=/^\S$/;
if (!value) return "";
if(value.length==0)
return value;
else
{
var lp,rp;
lp=0;rp=value.length-1;
while ((value.charAt(lp)==" "||(value.charCodeAt(lp)<128?(reg.test(value.charAt(lp))==false?true:false):false)||value.charAt(rp)==" "||(value.charCodeAt(rp)<128?(reg.test(value.charAt(rp))==false?true:false):false))&&rp>=lp)
{
if (value.charAt(lp)==" "||value.charCodeAt(lp)<128?(reg.test(value.charAt(lp))==false?true:false):false)
lp++;
if (value.charAt(rp)==" "||value.charCodeAt(rp)<128?(reg.test(value.charAt(rp))==false?true:false):false)
rp--;
}
if(lp>rp)
return "";
else
return (value.substring(lp,rp+1));
}
}
引用
邵波的空間 的 Java實現(xiàn)給圖片添加水印
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;public class WaterMark ...{
/** *//**
* 給圖片添加水印
* @param filePath 需要添加水印的圖片的路徑
* @param markContent 水印的文字
* @param markContentColor 水印文字的顏色
* @param qualNum 圖片質(zhì)量
* @return
*/
public boolean createMark(String filePath,String markContent,Color markContentColor,float qualNum,String watermark)
...{
ImageIcon imgIcon=new ImageIcon(filePath);
Image theImg =imgIcon.getImage();
int width=theImg.getWidth(null);
int height= theImg.getHeight(null);
//ImageIcon waterIcon=new ImageIcon(watermark);
//Image waterImg =waterIcon.getImage();
BufferedImage bimage = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
Graphics2D g=bimage.createGraphics();
g.setColor(markContentColor);
g.setBackground(Color.white);
g.drawImage(theImg, 0, 0, null );
//g.drawImage(waterImg, width*2, height, null );
g.drawString(markContent,width-100,height-30); //添加水印的文字和設(shè)置水印文字出現(xiàn)的內(nèi)容
g.dispose();
try...{
FileOutputStream out=new FileOutputStream(filePath);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
param.setQuality(qualNum, true);
encoder.encode(bimage, param);
out.close();
}catch(Exception e)
...{ return false; }
return true;
}
public static void main(String arg[])
...{
WaterMark wk=new WaterMark();
if(wk.createMark("D:\1.jpg","Welcome!",Color.WHITE,70f,""))...{
System.out.println("制作成功");
}else...{
System.out.println("失敗了!");
}
}
}
引用
邵波的空間 的 如何防止同一個賬戶被多個人同時登陸?
1.用session超時,session為null就表示下線了
2.也可以采用數(shù)據(jù)庫中設(shè)置 臨時表 來處理
一個用戶登陸時向表中插進(jìn)一條記錄,用戶離開時候刪除該記錄
如想統(tǒng)計在線人數(shù),簡單地執(zhí)行
select count(*) from table... 即可
3.application對象中可以記住現(xiàn)在的人數(shù),application的生命周期和服務(wù)器的生命周期一樣長。
4.還有一種方法要用到一個文件global.jsa ,方法是(在JSP中)是sessionDestroy(),其中它是以session對象為參數(shù)的。還有要把global.jsa文件必須房子和JSP 程序 相同的文件目錄內(nèi)才行。
5.網(wǎng)頁自動刷新的代碼是:
在文件頭部加上
<meta http-equiv="refresh" content="15">
刷新間隔時間是15秒
6.在session中加入監(jiān)聽類,類的示例代碼如下:onLineUser.java-------------------------------------------------------------------------------------------
package com.shaobo.struts.action;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;public class onLineUser implements HttpSessionBindingListener {
public onLineUser() {
}private Vector users = new Vector();
public int getCount() {
users.trimToSize();
return users.capacity();
}public boolean existUser(String userName) {
users.trimToSize();
boolean existUser = false;
for (int i = 0; i < users.capacity(); i++) {
if (userName.equals((String) users.get(i))) {
existUser = true;
break;
}
}
return existUser;
}public boolean deleteUser(String userName) {
users.trimToSize();
if (existUser(userName)) {
int currUserIndex = -1;
for (int i = 0; i < users.capacity(); i++) {
if (userName.equals((String) users.get(i))) {
currUserIndex = i;
break;
}
}
if (currUserIndex != -1) {
users.remove(currUserIndex);
users.trimToSize();
return true;
}
}
return false;
}public Vector getOnLineUser() {
return users;
}public void valueBound(HttpSessionBindingEvent e) {
users.trimToSize();
if (!existUser(e.getName())) {
users.add(e.getName());
System.out.print(e.getName() + "\t登入到系統(tǒng)\t"
+ (new Date()));
System.out.println("在線用戶數(shù)為:" + getCount());
} else
System.out.println(e.getName() + "已經(jīng)存在");
}public void valueUnbound(HttpSessionBindingEvent e) {
users.trimToSize();
String userName = e.getName();
deleteUser(userName);
System.out.print(userName + "\t退出系統(tǒng)\t" + (new Date()));
System.out.println("在線用戶數(shù)為:" + getCount());
}
}login.jsp--------------------------------------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><jsp:useBean id="onlineuser" class="com.shaobo.struts.action.onLineUser"
scope="application" />
<html>
<head>
</head>
<body onUnload="postMessage()">
<center>
<p>
<h1>
登陸成功,歡迎訪問
</h1>
</p>
</center>
<%
session = request.getSession(false);
%>
<%
String username = request.getParameter("username");
if (onlineuser.existUser(username)) {
out.println("用戶<font color=red>" + username
+ "</font>已經(jīng)登陸!");
} else {
session.setMaxInactiveInterval(50); //Sesion有效時長,以秒為單位
session.setAttribute(username, onlineuser);
out.println("歡迎新用戶:<font color=red>" + username
+ "</font>登陸到系統(tǒng)!");
}
out.println("<br>當(dāng)前在線用戶人數(shù):<font color=red>"
+ onlineuser.getCount() + "</font><br>");
String ip = request.getRemoteAddr();
out.println("<br>IP:<font color=red>" + ip + "</font><br>");
Vector vt = onlineuser.getOnLineUser();
Enumeration e = vt.elements();
out.println("在線用戶列表");
out.println("<table border=1>");
out.println("<tr><td>用戶名</td></tr>");
while (e.hasMoreElements()) {
out.println("<tr><td>");
out.println((String) e.nextElement() + "<br>");
out.println("</td></tr>");
}
out.println("</table>");
%>
<center>
<p>
</p>
[
<a href="javascript:window.close()">關(guān)閉窗口</a>]
<%
out.println("<p><a href='index.jsp'>退出系統(tǒng)</a></p>");
%>
</center>
<Script>
function postMessage(){
<%onlineuser.deleteUser(request.getParameter("username"));%>
}
</Script>
</body>
</html>歡迎光臨邵波的空間` http://blog.sina.com.cn/shaobolive
QQ:343269876