标签: struts2

Struts 2中的过滤器与拦截器

真的,过滤器和拦截器之间有什么区别?我意识到拦截器会在动作之前和之后触发,递归,并且过滤器可以配置为触发动作和某些url模式.但是你怎么知道何时使用每一个?

在我正在阅读Struts 2的书中,似乎拦截器正在被推动,我甚至按照教程编写了一个Authentication Interceptor以确保用户已登录.但是,如果用户试图访问一个不能访问的URL没有与之关联的动作,拦截器没有抓住它,这意味着我必须将动作与我想要保护的每个jsp相关联.这似乎不对.

我可以创建一个处理URL的身份验证过滤器,这样我就不必这样做了,但那么,拦截器有什么意义呢?

struts2 filter interceptor

22
推荐指数
2
解决办法
4万
查看次数

web.xml中的白名单安全性约束

我正在使用Tomcat作为我的Struts2应用程序.在web.xml如下所示具有一定的条目:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>restricted methods</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>TRACE</http-method>
    </web-resource-collection>
    <auth-constraint />
</security-constraint>
<security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/jsp/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>
    <security-constraint>
   <web-resource-collection>
       <web-resource-name>no_access</web-resource-name>
       <url-pattern>/myrrunner/*</url-pattern>
   </web-resource-collection>
   <auth-constraint/>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

如何更改上面列入黑名单的部分只使用白名单部分...例如,我需要将其他方法列入白名单,而不是黑名单PUT,DELTE但我不确定将它们列入白名单的语法以及将它们列入白名单的方法.

对于我上面的web.xml片段,我会很感激,如果有人可以为我提供whitelisitng对应部分xml.

编辑:另外,我如何真正验证解决方案是否有效?

谢谢

java tomcat web.xml struts2 security-constraint

22
推荐指数
2
解决办法
4万
查看次数

如何禁用struts 2 Form生成表格?

Struts 2自动为它的<s:form>标签生成HTML表.我该如何禁用它?任何帮助将不胜感激.谢谢.

java struts2

20
推荐指数
2
解决办法
1万
查看次数

使用Struts 2迭代HashMap <String,ArrayList <String >>

我目前在Struts2和s:iterate标签方面遇到了一些困难.

我想显示一个标签,它是HashMap中的关键字,后面跟着一个表(HashMap中的值),其中包含了对于HashMap中每个元素的ArrayList中的每个元素.

例如,

     label
  ----------
  | test1  |
  ----------
  | test2  |
  ----------



    label2
  ----------
  | test1  |
  ----------
  | test2  |
  ----------
Run Code Online (Sandbox Code Playgroud)

我看了很多关于HashMap的例子,但没有找到我的案例.

我怎样才能做到这一点 ?

谢谢,

java iterator struts2

20
推荐指数
1
解决办法
3万
查看次数

缺少工件javax.transaction:jta:jar:1.0.1B(问题不同,因为您可能会看到分辨率不同)

我正在尝试使用此处的示例来学习Hibernate-Spring-Struts .

但在创建pom.xml获取此错误后:

Missing artifact javax.transaction:jta:jar:1.0.1B
Run Code Online (Sandbox Code Playgroud)

我仅在创建pom.xml文件方面取得了进展,并进行了更改以包含最新的库.这是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>S3HMaven</groupId>
<artifactId>S3HMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>S3HMaven</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.0.1B</version>
    </dependency>

    <!-- Struts 2 -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.1.8</version>
    </dependency>

    <!-- Struts 2 + Spring plugins -->
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-spring-plugin</artifactId>
        <version>2.3.15.2</version>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.26</version>
    </dependency>

    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate struts2 maven

18
推荐指数
3
解决办法
5万
查看次数

struts2 - 理解值栈

我有一个关于struts2值栈的问题.假设我有一个Action类RegisterAction,它有一个execute方法,如下所示:

public String execute() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(new String("test string"));
    return SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

我的struts.xml看起来像这样:

<struts>
    <package name="default" extends="struts-default">
        <action name="*Register" method="{1}" class="vaannila.RegisterAction">
            <result name="populate">/register.jsp</result>
            <result name="input">/register.jsp</result>
            <result name="success">/success.jsp</result>
        </action>        
        <action name="*Test" method="{1}" class="vaannila.TestAction">
            <result name="test">/test.jsp</result>
            <result name="success">/success2.jsp</result>
        </action>        
    </package>
</struts>
Run Code Online (Sandbox Code Playgroud)

因此,在该类中执行execute方法后,控制将流向success.jsp.

我的问题是:

1)如何获得我在堆栈中推送的值success.jsp

2)让我们说success.jsp我有一个<s:submit method="testMethod" />重定向到一个名为的动作类TestAction.换句话说,从Register页面,用户单击submit,并在我们的执行方法中RegisterAction推送堆栈上的"测试字符串".然后我们去success.jsp.该success.jsp有一个提交按钮,指导我们TestAction#testMethod.在TestAction#testMethod,我RegisterAction#execute仍然在堆栈上推送的值是什么?我怎么才能得到它?我逐步完成了eclipse调试器,但我没有看到它的价值.

谢谢.

java struts2 valuestack

17
推荐指数
1
解决办法
3万
查看次数

在哪里放struts.xml

使用Struts2,我们必须struts.xml在类路径中,因此它不再适用于WEB-INF.所以我让我的项目部署的方式是坚持下去WEB-INF/classes并让它包括在内../struts2.xml

2个问题:

  1. 当我进行重建时,Eclipse会清除classes文件夹,因此会删除它 struts.xml
  2. Eclipse没有在我的项目浏览器中显示classes文件夹,所以它首先粘贴配置文件是一个不好的地方.

Struts2 Eclipse开发人员如何做到这一点?

struts2 configure

16
推荐指数
1
解决办法
3万
查看次数

错误"HttpServletRequest引用缺少的类型字符串"

我正在struts中实现一个项目,我在JSP页面中收到错误.

我已经在Eclipce IDE中配置了Tomcat 6,JRE和JDK 6.

代码是:

%request.getContextPath()%
Run Code Online (Sandbox Code Playgroud)

错误是:

The method getContextPath() from the type HttpServletRequest refers to the missing type String
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

java jsp servlets struts2

16
推荐指数
2
解决办法
4万
查看次数

#{} $ {}和%{}之间有什么区别?

我目前正在Struts2的工作,我只是不明白有什么区别之间${var},#{var}%{var}他们是不同的范围?他们什么?

我找到了一个#的例子:

<s:select label="Year"
      id="%{param.name}"
      list="#{'2010':'2010','2011':'2011','2012':'2012','2013':'2013','2014':'2014', '2015':'2015'}"
      value="%{currentYear}"
      required="true"
/>
Run Code Online (Sandbox Code Playgroud)

在这里,它看起来像是一个关联数组,但有时候我已经看到它#var(没有括号)任何想法?

java variables jsp struts2

16
推荐指数
1
解决办法
5184
查看次数

15
推荐指数
2
解决办法
5万
查看次数