本文整理匯總了Java中org.eclipse.jetty.server.Request.getParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.getParameter方法的具體用法?Java Request.getParameter怎麽用?Java Request.getParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.server.Request
的用法示例。
在下文中一共展示了Request.getParameter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handle
import org.eclipse.jetty.server.Request; //導入方法依賴的package包/類
@Override
public void handle(String target, Request req, HttpServletRequest sReq,
HttpServletResponse res) throws IOException, ServletException {
if (target.equals("/")) target = "/index.html";
String mime = getMIME(target);
DataSet ds = TempMonitor.getSensor().getData();
res.setContentType(mime + ";charset=utf-8");
if (target.startsWith("/api.json")) {
try (PrintWriter bw = res.getWriter()) {
String typeParam = req.getParameter("type");
if (typeParam == null) {
bw.println(
String.format(
"{\"temp\":\"%s\",\"hum\":\"%s\",\"pres\":\"%s\",\"port\":%s}",
String.valueOf(ds.getTemperature()),
String.valueOf(ds.getHumidity()),
String.valueOf(ds.getPressure()),
conf.getProperty("Socket_Port", "8888")
)
);
} else {
APIType type = getAPIType(typeParam);
String[] apiData = api.handle(type);
bw.println(
String.format(
"{\"format\":\"%s\",\"label1\":%s,\"label2\":%s,\"data\":[%s,%s,%s]}",
getFormat(type),
apiData[0],
apiData[1],
apiData[2],
apiData[3],
apiData[4]
)
);
}
}
} else {
if (TempMonitor.class.getResource(TempMonitor.HTTP_SOURCE + target) == null || mime.equals("")) {
res.setStatus(404);
return;
}
try (InputStream is = TempMonitor.class.getResourceAsStream(TempMonitor.HTTP_SOURCE + target);
OutputStream os = res.getOutputStream()) {
byte[] buf = new byte[1000];
for (int nChunk = is.read(buf); nChunk != -1; nChunk = is.read(buf))
os.write(buf, 0, nChunk);
}
}
}