java - 如何防止直接 URL 访问操作类

标签 java jsp struts2

<分区>

我正在开发一个购物网站应用程序。在我的应用程序中,我需要阻止对我的操作类的直接 URL 访问。例如,我有一个名为 OrderAdd 的操作。在此操作类中,我从请求范围获取一些数据。如果有人直接访问这个 Action 类,它会显示 Nullpointer 异常。我如何在我的应用程序中防止这种情况。有什么可能的方法吗?我正在使用 jsp 作为我的观点。我的框架是struts2。 Action 是 java。

提前致谢!

最佳答案

j2ee 中内置了安全约束。您可以在 web.xml 中配置您不想允许直接访问的 URL 模式..

阅读这里 http://java.dzone.com/articles/understanding-web-security

Source :

用例:我们想从任何访问中排除一组网络资源。当 Web 应用程序的特定部分需要进行某种形式的维护或不适用于通用 Web 应用程序的特定物理部署时,就会出现这种情况。我们将通过不指定任何角色的授权约束来实现这一点。

<security-constraint>
   <display-name>excluded</display-name>
   <web-resource-collection>
      <web-resource-name>No Access</web-resource-name>
      <url-pattern>/excluded/*</url-pattern>
      <url-pattern>/restricted/employee/excluded/*</url-pattern>
      <url-pattern>/restricted/partners/excluded/*</url-pattern>
   </web-resource-collection>
   <web-resource-collection>
      <web-resource-name>No Access</web-resource-name>
      <url-pattern>/restricted/*</url-pattern>
      <http-method>DELETE</http-method>
      <http-method>PUT</http-method>
      <http-method>HEAD</http-method>
      <http-method>OPTIONS</http-method>
      <http-method>TRACE</http-method>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
   </web-resource-collection>
   <auth-constraint />
   <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
   </user-data-constraint>
</security-constraint>

关于java - 如何防止直接 URL 访问操作类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20614015/

相关文章:

jsp - 如何响应 JSP Servlet 请求的自定义字符串

java - 使用 jquery 或 jsp 或 javascript 在 html 中显示 Windows 目录结构。

javascript - struts2中如何使用arraylist显示 "no result found"

javascript - 使用 AJAX 从 JSP 页面调用 Action 类

Java Android mysql 连接不适用于 4.0

java - 使用正则表达式删除java中分隔符之间的文本

java - Spring无法使用javax.servlet编译jsp

java - 如何在 JSP 中显示从 Hibernate 查询获得的列表

java - 验证模拟对象的方法

java.lang.ClassNotFoundException : org. apache.poi.POIXMLTypeLoader 错误