`

servlet 线程安全 application.setattribute,加上synchronized

    博客分类:
  • java
 
阅读更多
http://www.alixixi.com/Dev/Web/JSP/jsp7/2007/2007020914328.html

servletContext application=getServletContext();

后面的一段函数是env.java的片断,可以看看在servlet中如何使用application变量的。

Integer count = null;

synchronized (application) {

  count = (Integer) application.getAttribute("change");

  if (count == null)

    count = new Integer(0);

  count = new Integer(count.intValue() + 1);

  application.setAttribute("change", count);

}


分享到:
评论

相关推荐

    request.setAttribute 语句前总显示红色感叹号解决办法 HTTP Status 500 -

    - **异常详情**:`javax.servlet.ServletException: Servlet execution threw an exception` - **根本原因**:`java.lang.Error: Unresolved compilation problem: The method setAttribute(String, Object) in the ...

    javax.servlet.jsp-api-2.3.2-b01.jar.zip

    【javax.servlet.jsp-api-2.3.2-b01.jar.zip】这个压缩包文件包含的是Java服务器页面(JSP)的Servlet API,具体版本为2.3.2-b01。这个API主要用于网络应用程序开发,特别是针对基于Java的Web应用。在JSP中,开发者...

    javax.servlet.jsp.jstl-1.2.zip

    request.setAttribute("list", list); %> ${list}"> ${item} ``` 在这个例子中,`<c:forEach>`标签用于遍历集合,并通过EL表达式`${list}`引用了页面范围内的`list`变量。 总的来说,JSTL为JSP开发提供了...

    通过JavaScript下载文件到本地的方法(单文件)

    最近在做一个文件下载的功能,这里把做的过程中用... elt.setAttribute('href', url); elt.setAttribute('download', 'file.png'); elt.style.display = 'none'; document.body.appendChild(elt); elt.click(); d

    JSP request.setAttribute()详解及实例

    javascript request.setAttribute()详解 request.setAttribute()怎么用的? JSP1代码 String [] test=new String[2]; test[0]=1; test[1]=2; request.setAttribute(test,test) ; response.sendRedirect(jsp2.jsp); ...

    Servlet帮助中文文档.rar

    9. **安全性**:Servlet可以通过`HttpServletRequest`的`getUserPrincipal()`方法获取认证用户信息,配合`HttpServletRequest`的`isUserInRole()`检查权限,实现基于角色的访问控制。 10. **性能优化**:通过合理的...

    javaee试验二Servlet程序设计知识.pdf

    5. 实现验证码生成Servlet,确保登录安全。 6. 使用HttpSession保存验证码和用户名,方便后续操作。 7. 通过ServletContext访问外部资源,处理页面跳转。 8. 编写过滤器,检查登录状态并阻止非法访问。 9. 使用...

    struts乱码问题

    HttpServletRequest request=... session.setAttribute("bookName", this.bookName); session.setAttribute("bookPrice", this.bookPrice); session.setAttribute("bookPress", this.bookPress); return SUCCESS;

    jsp&servlet应用开发知识.pdf

    5. **Application**:代表整个Web应用,用于在整个应用范围内共享数据,如`application.getAttribute()`。 6. **Page**:代表当前的JSP页面,相当于`this`关键字,但不常用。 7. **Out**:用于向响应输出流写入...

    js四级联动完整代码

    form.certType.setAttribute("subElement", "certName"); //form.certType.setAttribute("selectedValue", 739); form.certType.setAttribute("defaultText", "不限1级"); form.certType.setAttribute("default...

    JSP与Servlet实现用户登录.rar

    在IT行业中,Web开发是至关重要的领域,而Java平台提供了强大的工具来构建动态网页应用,如JSP(JavaServer Pages)和Servlet。本项目聚焦于使用IntelliJ IDEA这一高效集成开发环境,通过JSP和Servlet实现用户登录...

    servlet服务应用基础.docx

    转发过程中,可以使用`request.setAttribute()`存储数据,然后在目标Servlet中使用`request.getAttribute()`获取。 - **重定向**(外部跳转):通过`response.sendRedirect()`方法实现,地址栏会显示新的URL,不...

    JSP登录1[servlet+bean].rar

    - 如果验证成功,Servlet会设置session属性,如`session.setAttribute("user", userBean)`,以便在后续请求中识别已登录的用户。 - 最后,Servlet通过响应重定向或转发到相应的结果页面,如登录成功页或错误提示页...

    servlet2.4doc

    Notification that the web application initialization process is starting. Cookie - class javax.servlet.http.Cookie. Creates a cookie, a small amount of information sent by a servlet to a Web browser,...

    SpringMvc初步入门简单的例子

    import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse...

    7. jsp内建对象之application

    `application`对象代表了Servlet的`javax.servlet.ServletContext`接口,它提供了对整个Web应用程序的访问。这个对象在整个Web应用的生命周期中只存在一个实例,因此可以用来存储和共享在整个应用范围内的数据。以下...

    jsp留言版-application

    - 使用`application`对象要注意数据安全,因为它共享所有用户的数据,避免存储敏感信息。 - 需要管理好数据的生命周期,避免数据量过大导致内存占用过多。 - 对于多用户的并发访问,需要考虑同步问题,防止数据...

    访问或添加三个范围的属性与获取Request-Session-ServletContext-Response对象.rar

    这些对象在Servlet编程中起到关键作用,帮助开发者在不同范围内存储和共享数据。 1. HttpServletRequest对象: Request对象代表客户端的HTTP请求,用于获取请求参数、请求头、请求路径等信息。通过`request....

    实验6 Servlet 二1

    多个Servlet对象共享数据新建两个不同的Servlet,在一个Servlet中通过ServletContext.setAttribute()设置一个全局属性

Global site tag (gtag.js) - Google Analytics