📄 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 + -