本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getServletContext方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getServletContext方法的具體用法?Java HttpServletRequest.getServletContext怎麽用?Java HttpServletRequest.getServletContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getServletContext方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
PrintWriter pw = resp.getWriter();
ServletContext sc = req.getServletContext();
pw.println("01-" + sc.getContext("/bar").getInitParameter("id"));
pw.println("02-" + sc.getContext("/foo").getInitParameter("id"));
pw.println("03-" + sc.getContext("/foo##1").getInitParameter("id"));
pw.println("04-" + sc.getContext("/foo##2").getInitParameter("id"));
pw.println("05-" + sc.getContext("/foo##3").getInitParameter("id"));
pw.println("06-" + sc.getContext("/unknown").getInitParameter("id"));
pw.println("07-" + sc.getContext("/").getInitParameter("id"));
pw.println("08-" + sc.getContext("/foo/bar").getInitParameter("id"));
pw.println("09-" + sc.getContext("/football").getInitParameter("id"));
}
示例2: doGet
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
//get the response writer
PrintWriter out = response.getWriter();
//initialise the servlet context
ServletContext context = request.getServletContext();
//get the context name
String lname = context.getServletContextName();
//initialise the parameters
String a = context.getInitParameter("a");
String b = context.getInitParameter("b");
String c = context.getInitParameter("c");
String d = context.getInitParameter("d");
Enumeration<String> e1 = context.getInitParameterNames();
String param_Names = "";
//appending attr names to a string variable
while(e1.hasMoreElements()) {
param_Names = param_Names + e1.nextElement()+"<br>";
}
//set the attribute
context.setAttribute("x", "XXX");
context.setAttribute("y", "YYY");
context.setAttribute("z", "ZZZ");
String x = (String)context.getAttribute("x");
String y = (String)context.getAttribute("y");
String z = (String)context.getAttribute("z");
//get the attribute names
Enumeration<String> e2 = context.getAttributeNames();
String attr_Names = "";
//appending attr names to a string variable
while(e2.hasMoreElements()) {
attr_Names = attr_Names + e2.nextElement()+"<br>";
}//while close
//html code to display
out.println("<html>");
out.println("<body>");
out.println("<h3>Servlet Context Details<h3>");
out.println("<table border='1'>");
out.println("<tr><td colspan='2'>Parameters Details</td></tr>");
out.println("<tr><td>a</td><td>"+a+"</td></tr>");
out.println("<tr><td>b</td><td>"+b+"</td></tr>");
out.println("<tr><td>c</td><td>"+c+"</td></tr>");
out.println("<tr><td>d</td><td>"+d+"</td></tr>");
out.println("<tr><td>Parameter Names</td><td>"+param_Names+"</td></tr>");
out.println("<tr><td colspan='2'>Attributes Details</td></tr>");
out.println("<tr><td>x</td><td>"+x+"</td></tr>");
out.println("<tr><td>y</td><td>"+y+"</td></tr>");
out.println("<tr><td>z</td><td>"+z+"</td></tr>");
out.println("<tr><td>Attributes Names</td><td>"+attr_Names+"</td></tr>");
out.println("<tr><td>Logical Name</td><td>"+lname+"</td></tr>");
out.println("<tr><td>Foreign Context</td><td>"+context.getContext("/app8")+"</td></tr>");
out.println("</table></body></html>");
}
示例3: init
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
* Method for stream initialization
* @param clientUri - Client Uri
* @param request - The servlet request object
* @param response - The servlet Response Object
*/
private void init(String clientUri,HttpServletRequest request, HttpServletResponse response){
LOG.info("Response Stream Inititated");
try{
HttpSession session = request.getSession();
session.setMaxInactiveInterval(72*60*60);
EventClient client = new EventClient();
client.connectToClient(clientUri);
response.setHeader("Content-Type", "text/event-stream");
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Connection", "keep-alive");
AsyncContext asyncContext = request.startAsync(request,response);
asyncContext.setTimeout(72*60*60*1000);
asyncContext.getResponse().setBufferSize(1200);
try {
asyncContext.getResponse().flushBuffer();
} catch (IOException e1) {
ErrorLog.logError(e1.getMessage(),e1.getStackTrace());
}
ServletContext servletContext = request.getServletContext();
Map<String,AsyncContext> responseStreams = (ConcurrentHashMap<String,AsyncContext>) servletContext.getAttribute("responseStreams");
responseStreams.put(clientUri,asyncContext);
} catch (Exception e){
ErrorLog.logError(e.getMessage(),e.getStackTrace());
}
}
示例4: upladNoteImage
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/uploadNoteImage")
@ResponseBody
public void upladNoteImage(@RequestParam("upload") MultipartFile img, HttpServletRequest request, HttpServletResponse response)throws IOException{
ServletContext servletContext = request.getServletContext();
response.setContentType("text/html;charset=UTF-8");
response.setHeader("X-Frame-Options", "SAMEORIGIN");
PrintWriter out = response.getWriter();
String CKEditorFuncNum = request.getParameter("CKEditorFuncNum");
String imgName = Long.toString(System.currentTimeMillis()) + img.getOriginalFilename();
String destPath = servletContext.getRealPath("/image/note/") + imgName;
img.transferTo(new File(destPath));
out.println("<script type=\"text/javascript\">");
out.println("window.parent.CKEDITOR.tools.callFunction("
+ CKEditorFuncNum + ",'" + "/teamnote/image/note/" + imgName
+ "','')");
out.println("</script>");
}
示例5: preHandle
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
ServletWebRequest wr = new ServletWebRequest(req);
ServletContext sctx = req.getServletContext();
String dbname = (String) sctx.getAttribute("dbname");
Connection dbconn = (Connection) wr.getAttribute("dbconn", WebRequest.SCOPE_REQUEST);
if (Objects.isNull(dbconn) && !Strings.isEmpty(dbname)) {
dbconn = DataStore.getConnection(dbname);
wr.setAttribute("dbconn", dbconn, WebRequest.SCOPE_REQUEST);
}
return super.preHandle(req, res, handler);
}
開發者ID:SecureSkyTechnology,項目名稱:burpextender-proxyhistory-webui,代碼行數:13,代碼來源:JdbcConnectionInterceptor.java
示例6: beforeRender
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected void beforeRender(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
ServletContext servletContext = request.getServletContext();
if (ConsoleRenderer.servletContext == null) {
ConsoleRenderer.servletContext = servletContext;
}
}
示例7: uploadavatar
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/uploadAvatar")
public String uploadavatar(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {
ServletContext servletContext = request.getServletContext();
String avatarName = Long.toString(System.currentTimeMillis()) + file.getOriginalFilename();
String destPath = servletContext.getRealPath("/image/avatar/") + avatarName;
file.transferTo(new File(destPath));
int userId = getUserId();
userBasicService.updateavatar(userId, "/image/avatar/" + avatarName, servletContext.getRealPath("/"));
return "redirect:/settings";
}
示例8: uploadQrcode
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/uploadQrcode")
public String uploadQrcode(@RequestParam("qrcode") MultipartFile qrcode, HttpServletRequest request) throws IOException {
ServletContext servletContext = request.getServletContext();
String qrcodeName = Long.toString(System.currentTimeMillis()) + qrcode.getOriginalFilename();
String destPath = servletContext.getRealPath("/image/qrcode/") + qrcodeName;
qrcode.transferTo(new File(destPath));
int userId = getUserId();
userBasicService.updateQrcode(userId, "/image/qrcode/" + qrcodeName, servletContext.getRealPath("/"));
return "redirect:/settings";
}
示例9: deleteQrcode
import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping("/deleteQrcode")
public String deleteQrcode(HttpServletRequest request) {
ServletContext servletContext = request.getServletContext();
int userId = getUserId();
userBasicService.deleteQrcode(userId, servletContext.getRealPath("/"));
return "redirect:/settings";
}