getServletContext()空指针异常的原因


-
getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因getServletContext()空指针异常的原因
-
2019-11-08
-
2016-08-17
-
2014-03-07
-
2014-01-24
-
2013-08-20
-
2013-08-09
-
2013-07-29
-
2013-02-22
-
2012-09-03
32KB
XML轻松入门到精通
2007-09-03XML轻松入门到精通,CHM文件
7KB
jsp day1技术解析(servlet/jsp)课件下载
2011-08-22JSP request ---> service HttpSession ----> request.getSession(); ServletContext 1 ServletConfig.getServletContext(); 2 ServletContextEvent.getServletContext(); 3 HttpSession.getServletContext(); ------------------------------------------------ JSP Java Server Page java服务页面 更强大的Servlet Servlet升级 Servlet 问题 1 XXXViewServlet out.println("<html>"); out.println("</html>"); 不善于做显示页面 2 Java程序 java---> javac ---> 启动tomcat 修改繁琐
4.18MB
学生信息管理系统
2014-05-31protected void doPost HttpServletRequest request HttpServletResponse response throws ServletException IOException { String action request getParameter "action" ; Teacher t new Teacher ; t setUsername request getParameter "username" ; if "register" equals action { t setPassword MD5 generateMD5 request getParameter "password" ; if teacherDao add t >0 { request getSession setAttribute "mess" "恭喜 注册成功 " ; response sendRedirect "login jsp" ; }else{ response sendRedirect "error jsp" ; } }else if "login" equals action { t setPassword MD5 generateMD5 request getParameter "password" ; if teacherDao queryByTeacher t size >0 { Constants ONLINE COUNT++; Object oCount getServletContext getAttribute "count" ; if oCount null { getServletContext setAttribute "count" 1 ; }else{ getServletContext setAttribute "count" Integer getServletContext getAttribute "count" +1 ; } request getSession setAttribute "teacher" t ; request getSession setAttribute "students" studentDao queryStudentsByTeacher t ; if request getParameter "autoLogin" null { Cookie cookie1 new Cookie "username" t getUsername ; Cookie cookie2 new Cookie "password" t getPassword ; cookie1 setMaxAge 60 60 24 14 ; cookie2 setMaxAge 60 60 24 14 ; response addCookie cookie1 ; response addCookie cookie2 ; } response sendRedirect "index jsp" ; }else{ request setAttribute "mess" "用户名或密码错误 " ; request getRequestDispatcher "login jsp" forward request response ; } }else if "autoLogin" equals action { t setPassword request getParameter "password" ; if teacherDao queryByTeacher t size >0 { Constants ONLINE COUNT++; Object oCount getServletContext getAttribute "count" ; if oCount null { getServletContext setAttribute "count" 1 ; }else{ getServletContext setAttribute "count" Integer getServletContext getAttribute "count" +1 ; } request getSession setAttribute "teacher" t ; request getSession setAttribute "students" studentDao queryStudentsByTeacher t ; response sendRedirect "index jsp" ; }else{ request setAttribute "mess" "用户名或密码错误 " ; Cookie[] cookies request getCookies ; if cookies null { for Cookie cookie : cookies { if "username" equals cookie getName || "password" equals cookie getName { cookie setValue null ; 关键 cookie setMaxAge 0 ; response addCookie cookie ; } } } request getRequestDispatcher "login jsp" forward request response ; } }else if "loginOut" equals action { request getSession invalidate ; response sendRedirect "login jsp" ; } }">protected void doPost HttpServletRequest request HttpServletResponse response throws ServletException IOException { String action request getParameter "action" ; Teacher t new Teacher ; t setUsername request getParameter "username" ; if "register" equals ac [更多]
3KB
javaweb 做图片水印,水印图片到目录图片上去
2012-09-14添加水印方法(水印图片,目标图片),添加在右下角(根据坐标显示) 针对网页图片添加水印,用java语言编写,很简单。 // 获取水印图片的路径 String planeImage = request.getSession().getServletContext().getRealPath("/image").replace("\\", "/")+"/"+"symark.png"; //获取目标图片的路径String targetPic = request.getSession().getServletContext().getRealPath("/image").replace("\\", "/")+"/"+ad.getId()+"."+ad.getExttype(); //给目标图片加水印,name为水印图片,targetPic为目标图片addWaterImg(planeImage,targetPic); 不清楚邮件至:lcyangmi@163.com
32KB
request.getcontextPath()_详解
2012-10-22request.getcontextPath()详解
37KB
Oracle命令大全
2009-04-25Oracle命令大全private void init1(ServletConfig config) { try { Class userDaoClass = Class.forName(config .getInitParameter("userDao")); Object userDao = userDaoClass.newInstance(); Class userServiceClass = Class.forName(config .getInitParameter("userService")); Constructor cons1 = userServiceClass.getConstructor(UserDao.class); Object userService = cons1.newInstance(userDao); WebUtils.setUserService(config.getServletContext(), userService); Class articleDaoClass = Class.forName(config .getInitParameter("articleDao")); Object articleDao = articleDaoClass.newInstance(); Class articleServiceClass = Class.forName(config .getInitParameter("articleService")); Constructor cons2 = articleServiceClass.getConstructor( ArticleDao.class, UserDao.class); Object articleService = cons2.newInstance(articleDao, userDao); WebUtils.setArticleService(config.getServletContext(), articleService); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
42KB
ServLetContext基础
2021-01-08ServLetContext 解决的问题:不同的用户使用相同的数据 就是不同的用户,访问网页的时候能看到某一个相同的数据,例如该网站被访问的次数 其他特征: 特点:服务器创建;用户共享 作用域:整个项目 生命周期:服务器启动到服务器关闭 如何使用: 三种创建方式: ServletContext sc=this.getServletContext(); ServletContext sc1=this.getServletConfig().getServletContext(); ServletContext sc2=req.getSession().getServletContext(); 注意
174KB
Servlet知识点和示例
2014-01-04ServletContext对象 (1)WEB容器在启动时,它会为每个WEB应用程序都创建一个对应的ServletContext对象,它代表当前web 应用。 (2)ServletContext对象被包含在ServletConfig对象中,开发人员在编写servlet时,可以通过 this.ServletConfig.getServletContext方法获得对ServletContext对象的引用.还可以直接通过 this.getServletContext方法获得对ServletContext对象的引用. (3)由于一个WEB应用中的所有Servlet共享同一个ServletContext对象,因此Servlet对象之间可以通过 ServletContext对象来实现通讯。ServletContext对象通常也被称之为context域对象。 (4)context域对象:域在中文里面就是“范围”的意思,它是整个web应用的范围。还有request域、session域和page域。 (5)ServletContext对象可以获取一些全局的配置信息,例如数据库的一些信息,可以配置xml文件当中 ,之后,通过ServletContext对象获取。这样配置的好处是每个servlet都可以直接访问,而不需要为每 个servlet进行配置,显得繁琐。 (6)servletContext域:1,是一个容器 2。作用范围是应用程序范围
20.86MB
ssh-整合资料
2018-01-27可以通过 WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext()); 来获取
117KB
图片上传并回显插件
2017-09-08图片上传插件,可多文件上传和回显,可删除已上传图片,可进行拖拽上传。 springmvc接收传向后台的值方法 @RequestMapping("/admin/addImage.do") public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { MultipartResolver resolver = new CommonsMultipartResolver(request .getSession().getServletContext()); MultipartHttpServletRequest multipartRequest = resolver .resolveMultipart(request); MultipartFile file = multipartRequest.getFile("fileList"); 这个file就能获取前台post传出的值。
7.24MB
spring+hibernate+osworkflow
2008-12-17spring+hibernate+osworkflow,服务器为Tomcat6.0,数据库为Mysql 把viewlivegraph2.jsp改为viewlivegraph.jsp. 其中把wf的获得修改为 ApplicationContext cxt = WebApplicationContextUtils.getWebApplicationContext(this.getServletConfig().getServletContext()); Workflow wf = (Workflow)cxt.getBean("workflow"); 用osworkflow自带的designer把example重新生成一下图片和example.lyt.,然后把example.lyt.修改为example.lyt.xml,把这个文也给换了example.lyt.xml,然后替换原文件。
35KB
jsp内置对象的用法
2012-03-07jsp内置对象 定义:可以不加声明就在JSP页面脚本(Java程序片和Java表达式)中使用的成员变量 JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应): 1.request对象 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。 序号 方 法 说 明 1 object getAttribute(String name) 返回指定属性的属性值 2 Enumeration getAttributeNames() 返回所有可用属性名的枚举 3 String getCharacterEncoding() 返回字符编码方式 4 int getContentLength() 返回请求体的长度(以字节数) 5 String getContentType() 得到请求体的MIME类型 6 ServletInputStream getInputStream() 得到请求体中一行的二进制流 7 String getParameter(String name) 返回name指定参数的参数值 8 Enumeration getParameterNames() 返回可用参数名的枚举 9 String[] getParameterValues(String name) 返回包含参数name的所有值的数组 10 String getProtocol() 返回请求用的协议类型及版本号 11 String getScheme() 返回请求用的计划名,如:http.https及ftp等 12 String getServerName() 返回接受请求的服务器主机名 13 int getServerPort() 返回服务器接受此请求所用的端口号 14 BufferedReader getReader() 返回解码过了的请求体 15 String getRemoteAddr() 返回发送此请求的客户端IP地址 16 String getRemoteHost() 返回发送此请求的客户端主机名 17 void setAttribute(String key,Object obj) 设置属性的属性值 18 String getRealPath(String path) 返回一虚拟路径的真实路径 2.response对象 response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。 序号 方 法 说 明 1 String getCharacterEncoding() 返回响应用的是何种字符编码 2 ServletOutputStream getOutputStream() 返回响应的一个二进制输出流 3 PrintWriter getWriter() 返回可以向客户端输出字符的一个对象 4 void setContentLength(int len) 设置响应头长度 5 void setContentType(String type) 设置响应的MIME类型 6 sendRedirect(java.lang.String location) 重新定向客户端的请求 3.session对象 session对象指的是客户端与服务器的一次会话,从客户端连到服务器的一个WebApplication开始,直到客户端与服务器断开连接为止。它是HttpSession类的实例. 序号 方 法 说 明 1 long getCreationTime() 返回SESSION创建时间 2 public String getId() 返回SESSION创建时JSP引擎为它设的惟一ID号 3 long getLastAccessedTime() 返回此SESSION里客户端最近一次请求时间 4 int getMaxInactiveInterval() 返回两次请求间隔多长时间此SESSION被取消(ms) 5 String[] getValueNames() 返回一个包含此SESSION中所有可用属性的数组 6 void invalidate() 取消SESSION,使SESSION不可用 7 boolean isNew() 返回服务器创建的一个SESSION,客户端是否已经加入 8 void removeValue(String name) 删除SESSION中指定的属性 9 void setMaxInactiveInterval() 设置两次请求间隔多长时间此SESSION被取消(ms) 4.out对象 out对象是JspWriter类的实例,是向客户端输出内容常用的对象 序号 方 法 说 明 1 void clear() 清除缓冲区的内容 2 void clearBuffer() 清除缓冲区的当前内容 3 void flush() 清空流 4 int getBufferSize() 返回缓冲区以字节数的大小,如不设缓冲区则为0 5 int getRemaining() 返回缓冲区还剩余多少可用 6 boolean isAutoFlush() 返回缓冲区满时,是自动清空还是抛出异常 7 void close() 关闭输出流 5.page对象 page对象就是指向当前JSP页面本身,有点象类中的this指针,它是java.lang.Object类的实例 序号 方 法 说 明 1 class getClass 返回此Object的类 2 int hashCode() 返回此Object的hash码 3 boolean equals(Object obj) 判断此Object是否与指定的Object对象相等 4 void copy(Object obj) 把此Object拷贝到指定的Object对象中 5 Object clone() 克隆此Object对象 6 String toString() 把此Object对象转换成String类的对象 7 void notify() 唤醒一个等待的线程 8 void notifyAll() 唤醒所有等待的线程 9 void wait(int timeout) 使一个线程处于等待直到timeout结束或被唤醒 10 void wait() 使一个线程处于等待直到被唤醒 11 void enterMonitor() 对Object加锁 12 void exitMonitor() 对Object开锁 6.application对象 application对象实现了用户间数据的共享,可存放全局变量。它开始于服务器的启动, 直到服务器的关闭,在此期间,此对象将一直存在;这样在用户的前后连接或不同用户之间的连接中,可以对此对象的同一属性进行操作;在任何地方对此对象属性 的操作,都将影响到其他用户对此的访问。服务器的启动和关闭决定了application对象的生命。它是ServletContext类的实例。 序号 方 法 说 明 1 Object getAttribute(String name) 返回给定名的属性值 2 Enumeration getAttributeNames() 返回所有可用属性名的枚举 3 void setAttribute(String name,Object obj) 设定属性的属性值 4 void removeAttribute(String name) 删除一属性及其属性值 5 String getServerInfo() 返回JSP(SERVLET)引擎名及版本号 6 String getRealPath(String path) 返回一虚拟路径的真实路径 7 ServletContext getContext(String uripath) 返回指定WebApplication的application对象 8 int getMajorVersion() 返回服务器支持的Servlet API的最大版本号 9 int getMinorVersion() 返回服务器支持的Servlet API的最大版本号 10 String getMimeType(String file) 返回指定文件的MIME类型 11 URL getResource(String path) 返回指定资源(文件及目录)的URL路径 12 InputStream getResourceAsStream(String path) 返回指定资源的输入流 13 RequestDispatcher getRequestDispatcher(String uripath) 返回指定资源的RequestDispatcher对象 14 Servlet getServlet(String name) 返回指定名的Servlet 15 Enumeration getServlets() 返回所有Servlet的枚举 16 Enumeration getServletNames() 返回所有Servlet名的枚举 17 void log(String msg) 把指定消息写入Servlet的日志文件 18 void log(Exception exception,String msg) 把指定异常的栈轨迹及错误消息写入Servlet的日志文件 19 void log(String msg,Throwable throwable) 把栈轨迹及给出的Throwable异常的说明信息 写入Servlet的日志文件 7.exception对象 exception对象是一个例外对象,当一个页面在运行过程中发生了例外,就产生这个对象。如果一个JSP页面要应用此对象,就必须把isErrorPage设为true,否则无法编译。他实际上是java.lang.Throwable的对象 序号 方 法 说 明 1 String getMessage() 返回描述异常的消息 2 String toString() 返回关于异常的简短描述消息 3 void printStackTrace() 显示异常及其栈轨迹 4 Throwable FillInStackTrace() 重写异常的执行栈轨迹 8.pageContext对象 pageContext对象提供了对JSP页面内所有的对象及名字空间的访问,也就是说他可以访问到本页所在的SESSION,也可以取本页面所在的application的某一属性值,他相当于页面中所有功能的集大成者,它的本类名也叫pageContext。 序号 方 法 说 明 1 JspWriter getOut() 返回当前客户端响应被使用的JspWriter流(out) 2 HttpSession getSession() 返回当前页中的HttpSession对象(session) 3 Object getPage() 返回当前页的Object对象(page) 4 ServletRequest getRequest() 返回当前页的ServletRequest对象(request) 5 ServletResponse getResponse() 返回当前页的ServletResponse对象(response) 6 Exception getException() 返回当前页的Exception对象(exception) 7 ServletConfig getServletConfig() 返回当前页的ServletConfig对象(config) 8 ServletContext getServletContext() 返回当前页的ServletContext对象(application) 9 void setAttribute(String name,Object attribute) 设置属性及属性值 10 void setAttribute(String name,Object obj,int scope) 在指定范围内设置属性及属性值 11 public Object getAttribute(String name) 取属性的值 12 Object getAttribute(String name,int scope) 在指定范围内取属性的值 13 public Object findAttribute(String name) 寻找一属性,返回起属性值或NULL 14 void removeAttribute(String name) 删除某属性 15 void removeAttribute(String name,int scope) 在指定范围删除某属性 16 int getAttributeScope(String name) 返回某属性的作用范围 17 Enumeration getAttributeNamesInScope(int scope) 返回指定范围内可用的属性名枚举 18 void release() 释放pageContext所占用的资源 19 void forward(String relativeUrlPath) 使当前页面重导到另一页面 20 void include(String relativeUrlPath) 在当前位置包含另一文件 9.config对象 config对象是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一个ServletContext对象) 序号 方 法 说 明 1 ServletContext getServletContext() 返回含有服务器相关信息的ServletContext对象 2 String getInitParameter(String name) 返回初始化参数的值 3 Enumeration getInitParameterNames() 返回Servlet初始化所需所有参数的枚举
1KB
在action以外的地方获取dao
2011-05-30ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(); 或者 ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(); 这是在action以外的地方拿ApplicationContext的方法,需要的参数是:ServletContext,在request.getServletContext里能拿到,所以只要有request就能拿到spring配置文件里的bean. 这种方法通常在写组件时用,比如写个自定义标签,正常的流程,最后都走action,尽量保证每个请求都给一个.do,而不是直接去一个JSP,这样既保证了MVC模式,又防止用户直接记下JSP地址在没有后台准备情况下访问。
42KB
Struts源代码阅读.CHM
2007-06-29Struts 初始化 <br/>initInternal()方法: <br/>initOther()方法 <br/>initServlet()方法 <br/>getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this) <br/>ModuleConfig moduleConfig = initModuleConfig("", config) <br/>initModuleMessageResources(ModuleConfig config) <br/>initModuleDataSources(ModuleConfig config) <br/>initModulePlugIns(moduleConfig) <br/>初始化结束 <br/>2. Struts 的执行 <br/>RequestUtils.selectModule(String prefix, HttpServletRequest,ServletContext)方法 <br/>RequestUtils.selectModule(HttpServletRequest, ServletContext) <br/>getModuleConfig(HttpServletRequest) <br/>getRequestProcessor(ModuleConfig config)
4KB
fileutil工具类 处理文件流工具
2019-03-30fileutil工具类 处理文件流工具 private static File file; /** * 判断文件是否存在 * * @param path * 文件路径 * @return boolean */ public static boolean fileIsExists(String path) { if (path == null) return false; file = new File(path); return file.exists(); } /** * 判断服务器文件是否存在 * * @param path * 文件路径 * @param request * HttpServletRequest * @return boolean */ public static boolean fileIsExists(String path, HttpServletRequest request) { if (path == null) return false; file = new File(request.getServletContext().getRealPath(path)); return file.exists(); }
8KB
从HttpServletRequest获取各种路径总结
2017-11-01从HttpServletRequest获取各种路径总结.docx从HttpServletRequest获取各种路径总结.docx
-
下载
智慧酒店智能化信息化建设方案.pptx
智慧酒店智能化信息化建设方案.pptx
-
下载
考试重点工程项目管理重点{赠送}.pdf
考试重点工程项目管理重点{赠送}.pdf
-
下载
Huawei Certified Datacom Professional-Fast Certification(SU0-224)认证考试题库.docx
Huawei Certified Datacom Professional-Fast Certification(SU0-224)认证考试题库.docx
-
下载
全媒体融合教学案例平台解决方案.ppt
全媒体融合教学案例平台解决方案.ppt
-
下载
HCNA-BSSN(HC-611)认证考试题库.274q.docx
HCNA-BSSN(HC-611)认证考试题库.274q.docx
-
下载
KUKA系统变量().pdf
KUKA系统变量().pdf
-
下载
RTS5732DL_Bics3.rar
RTS5732DL_Bics3.rar
-
下载
Lux URP Essentials 1.7.unitypackage
Lux URP Essentials 1.7.unitypackage
-
下载
com.jc.elastic-1.0.0-01.aarch64.rpm
com.jc.elastic-1.0.0-01.aarch64.rpm
-
下载
ISO/IEC/IEEE 24748-6:2016 系统和软件工程--生命周期管理--第6部分:系统集成工程 - 完整英文版(41页)
ISO/IEC/IEEE 24748-6:2016 系统和软件工程--生命周期管理--第6部分:系统集成工程 - 完整英文版(41页)
