用servlet顯示圖片

下在這個 1.htm 用來調用servlet


<!------------ 文件 1.htm 開始-------------------->
<html>
<head><title>用servlet 顯示圖片</title></head>

<body>

<img src="http://localhost:8080/servlet/showimage">

</body>
</html>

<!------------ 文件 1.htm 結束 ---------------->

在Servlet 中,是靠 doGet()、 doPost() 等方法來響應 GET POST 方法的,這裏我們響應的是GET,所以定義了一個 doGet() 方法下面是源程序:

//====================== showimage.java 程序開始 ===================================

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class showImage extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{

try{
FileInputStream hFile = new FileInputStream("d:\\1.gif"); // 以byte流的方式打開文件 d:\1.gif
int i=hFile.available(); //得到文件大小
byte data[]=new byte<i>;
hFile.read(data); //讀數據
hFile.close();
res.setContentType("image/*"); //設置返回的文件類型
OutputStream toClient=res.getOutputStream(); //得到向客戶端輸出二進制數據的對象
toClient.write(data); //輸出數據
toClient.close();
}
catch(IOException e) //錯誤處理
{
PrintWriter toClient = res.getWriter(); //得到向客戶端輸出文本的對象
res.setContentType("text/html;charset=gb2312");
toClient.write("無法打開圖片!");
toClient.close();
}

}

}


發佈日期: 三, 23 八月 2006 14:01:21 GMT
計算機與 Internet |
閱讀完整項.

Decision&fork實例

Decision&fork實例

(一)Decision
package jonim.jbpm.delegation;
import org.jbpm.delegation.*;
import jonim.jbpm.LogsFactory;
import org.apache.commons.logging.Log;
import jonim.jbpm.Constants;

public class ChiefDecision implements DecisionHandler {
public ChiefDecision() {
}

/**
* 判斷是否需要主管批准,決定下一個要進行的transition
*
* @param executionContext ExecutionContext
* @return String
* @todo Implement this org.jbpm.delegation.DecisionHandler method
*/
public String decide(ExecutionContext executionContext) {
Log log=LogsFactory.getLogInstance(this.getClass());
String ac=(String)executionContext.getVariable(Constants.USER_NAME);
if(ac!=null&&(ac.equals("dali")||ac.equals("wang"))){
log.info(ac+"需要老闆批准!");
return "BossApprove";
}else{
log.info(ac+"需要先經主管批准");
return "ChiefApprove";
}
}
}

(二)fork
package jonim.jbpm.delegation;

import org.jbpm.*;
import org.jbpm.delegation.*;
import org.jbpm.model.execution.*;
import java.util.*;

public class DecidedJoin implements JoinHandler {
public DecidedJoin() {
}

/**
* fork,只要一個分支到達,即可進行下一步操作,同時取消其它同時進行的分支。
* 這裏就是用戶如果取消,請假就取消。如果用戶請假批准,則用戶不能取消。
*
* @param forkContext ForkContext
* @throws ExecutionException
* @todo Implement this org.jbpm.delegation.ForkHandler method
*/
public void join(JoinContext joinContext) throws ExecutionException {
Iterator it=joinContext.getConcurrentTokens().values().iterator();
Token arrivingToken = joinContext.getToken();
while(it.hasNext()){
Token to=(Token)it.next();
if(to.getId().equals(arrivingToken.getId())){
//取消其它執行的Token
joinContext.getExecutionService().cancelToken(to.getId());
}
}
// reactivate the parent token.
joinContext.reactivateToken( arrivingToken.getParent() );
}
}
發佈了15 篇原創文章 · 獲贊 0 · 訪問量 2941
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章