?? mainservlet.java
字號:
package com.j2medev.provision;
import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.*;
import javax.servlet.http.*;
public class MainServlet extends HttpServlet {
public static final String JAD_FILE = "helloworld.jad";
public static final String JAR_FILE = "helloworld.jar";
//替換為你的服務器地址
public static final String HOST = "http://localhost:8080";
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/vnd.wap.wml;charset=UTF-8");
//輸出HTTP Header
Enumeration headers = request.getHeaderNames();
while(headers.hasMoreElements()){
String header = (String)headers.nextElement();
String value = request.getHeader(header);
System.out.println(header+":"+value);
}
//判斷是否是應用程序安裝狀態的返回碼
String action = request.getParameter("action");
if(action != null){
System.out.println(action);
String id = request.getParameter("id");
System.out.println(id);
ServletInputStream is = request.getInputStream();
byte[] data = new byte[request.getContentLength()];
System.out.println("content-length="+request.getContentLength());
//讀取返回內容,通常是返回碼 描述信息的格式,例如900 Success
is.read(data);
System.out.println(new String(data));
return;
}
//存儲應用程序的根目錄
String path = getServletContext().getRealPath("/")+"ota";
Hashtable apps = new Hashtable();
File file = new File(path);
if(file.isDirectory()){
//列出存放MIDlet套件應用程序的目錄
File[] dirs = file.listFiles();
for(int i = 0;i<dirs.length;i++){
if(dirs[i].isDirectory()){
apps.put(dirs[i].getName(),HOST+request.getContextPath()+"/ota/"+dirs[i].getName()+"/"+JAD_FILE);
}
}
}
request.setAttribute("appsList",apps);
//將請求轉發給wml頁面顯示出來
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "OTA Download";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -