小编Ele*_*ist的帖子

Interceptor阻止URL参数传递给操作

我有一个在大多数操作之前运行的LoginInterceptor,并检查该成员是否已登录.如果是,则显示页面,否则重定向到登录页面.

但是我只是注意到拦截器"阻止"所有URL参数.基本上,如果在操作之前存在拦截器,则此操作的URL参数将不会传递给setter.

这是我的拦截器:

public class LoginInterceptor extends AbstractInterceptor {
    public String intercept(final ActionInvocation invocation) throws Exception {
        final String REDIR = "loginRedirect";
        AuthenticationService auth = new AuthenticationService();
        if (auth.isMemberLoggedIn()) {
            return invocation.invoke();
        } else {
            return REDIR;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我怀疑invocation.invoke()调用动作,但没有参数.

我能做些什么呢?

更新:

AuthenticationService.isMemberLoggedIn()

public boolean isMemberLoggedIn() {
    Map<String, Object> session = ActionContext.getContext().getSession();
    String username = (String) session.get("username");
    if (username != null) {
        return true;
    } else {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

在struts.xml

<package name="global" extends="struts-default">
    <interceptors>
        <interceptor …
Run Code Online (Sandbox Code Playgroud)

struts2 interceptor

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

与父组件通信

我有MyPage.tml页面和MyComponent.tml组件。

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
    <body>
        <t:mycomponent />
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

MyPage我需要根据 中发生的情况显示一些数据MyComponent。我怎样才能使一些数据MyComponent可用到MyPage?是否有类似“反向”参数(子级将参数传递给父级)之类的东西?

java tapestry

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

使用线程作为"会话"

我正在开发一个基于文本的游戏MUD.我已准备好程序的基本功能,现在我想允许一次连接多个客户端.我计划使用线程来实现这一目标.

在我的游戏中,我需要存储每个玩家的当前位置或健康点等信息.我可以把它放在数据库中,但是因为它会很快变化,有时候每一秒都会变得很低效(我是对的吗?).

我的问题是:线程可以表现为"会话",即保存每个用户独有的一些数据吗?

如果是的话,你能指导我一些我可以用来帮助我了解它是如何工作的资源吗?

如果不是,你有什么建议?数据库是一个不错的选择还是你会推荐其他东西?

干杯,Eleeist

java database multithreading mud

0
推荐指数
1
解决办法
695
查看次数

增加表单字段名称中的值

我需要验证X个字段.每个字段都命名为"testFieldX",其中X是大于1的任何实数.

所以基本上我在表单中的是具有名称的字段:

testField1
testField2
testField3
Run Code Online (Sandbox Code Playgroud)

等等

我需要遍历所有这些并验证.

我们假设我有5个字段.

然后

<cfloop index="i" from="1" to="5">
    <cfif form.testField & i EQ "">
        Show error
    </cfif>
</cfloop>
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我收到一个错误,即字段名称"testField"不存在,这是真的(只有testField1 +)存在.似乎事情并没有连接起来.它只适用于字符串吗?

我怎么解决这个问题?

coldfusion loops

0
推荐指数
1
解决办法
103
查看次数

使用ListToArray时更改数组启动索引

当我将列表转换为数组时,从索引1开始插入值.索引0保留为空.

为什么会发生这种情况,更重要的是,有没有办法改变它以便从0指数开始?

例:

<cfset myList = "A,B,C,D" />
<cfset myArray = ListToArray(myList) />
<cfdump var="#myArray#" />
Run Code Online (Sandbox Code Playgroud)

arrays coldfusion list

0
推荐指数
1
解决办法
103
查看次数

获取带变量的URL

我如何获取所请求页面的URL以及所有变量?我知道如何获取没有变量的URL.

例如./forums/index.cfm?id=10&cat=5

variables url coldfusion

0
推荐指数
1
解决办法
76
查看次数

Tapestry IoC构造函数和注入

我有以下课程:

public class MyClass {
    @Inject
    private MyAnotherClass myAnotherClass;

    public MyClass() {
        //Perform operations on myAnotherClass.
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要在构造函数中做一些需要实例的东西myAnotherClass.不幸的myAnotherClass是,在构造函数中的代码运行后注入,这意味着我正在执行操作null...

我当然可以MyAnotherClass myAnotherClass = new MyAnotherClass()直接在构造函数中将它实例化为经典的方式(),但我不认为在这种情况下做正确的事情.

你会建议什么解决方案来解决这个问题?

tapestry inversion-of-control

0
推荐指数
1
解决办法
194
查看次数