小编Rom*_*n C的帖子

OGNL数组和列表索引

我将此参数发送到我的struts动作

cdata [1] = bar

在我的操作中,我对索引和值感兴趣。我CDATA为OGNL文档所建议的定义了一个getter / setter对:

public void setCdata(int index, String value){
    LOG.info("setData; key="+ key +"; value="+ value);
    // store index and value;
}

public String getCdata(int index){
    return null; // don't really need a setter
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的异常:

2013-04-29 15:38:49,792 [http-apr-8080-exec-3] WARN  com.opensymphony.xwork2.util.logging.commons.CommonsLogger.warn(CommonsLogger.java:60) - Error setting expression 'cdata[1]' with value '[Ljava.
lang.String;@4223d2a4'
ognl.OgnlException: target is null for setProperty(null, "1", [Ljava.lang.String;@4223d2a4)
        at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2309)
        at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
        at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
        at ognl.SimpleNode.setValue(SimpleNode.java:301)
        at ognl.ASTChain.setValueBody(ASTChain.java:227)
        at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
        at ognl.SimpleNode.setValue(SimpleNode.java:301) …
Run Code Online (Sandbox Code Playgroud)

java struts2 ognl

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

获取元素属性的最佳方法是什么?

在大多数情况下,我和大多数新手Web开发人员一样使用jQuery,但更多时候我开始使用干净的js.所以从这里我的问题是:在jQuery范围中使用干净的js是上帝的做法,例如,如果我需要获取元素类,我可以这样做:

jQuery('div#grid a').click(function(event){
    event.preventDefault();
    console.log(this.getAttribute('class'));
    console.log(this.className);
    console.log(jQuery(this).attr('class'));
});
Run Code Online (Sandbox Code Playgroud)

但最好的方法是什么?

javascript jquery

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

MSDeploy跳过root web.config

我不能msdeploy只跳过root web.config(我想保留根目录下的子文件夹中存在的任何web.config文件)

这是我使用的参数:

-skip:objectName=filePath,absolutePath=^\\web\.config
Run Code Online (Sandbox Code Playgroud)

我试过了^\\web\.config,\\web\.config文件的绝对路径,例如:C:\\Some Path\\web\.config.这些似乎都不起作用.

msdeploy

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

JSF和类型安全

当我挣扎了好几个小时后,我终于找到了那些令人烦恼ClassCastException的东西来自哪里,我认为这些是由Hibernate制作的,而且它是enum映射的.

但是,他们都来自我的JSF视图,在这里我通过List从

    <h:selectManyCheckbox value="#{createUserManager.user.roles}"  ... >
        <f:selectItems value="#{createUserManager.roles}"/>
    </h:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)

回到我的支持bean.
我的数据只包含枚举的值: public Role[] getRoles() { return Role.values(); }.
当我roles在User-class中测试了setter 并得到了这个时,我感到非常震惊:

public void setRoles(List<Role> paramRoles) {

    System.out.println(paramRoles.get(0) instanceof Role); //output: false

    for(Role role : paramRoles){ ...} //crashes with ClassCastException
}
Run Code Online (Sandbox Code Playgroud)

更改List<Role> paramRoles到List<String> paramRoles完美.
这怎么可能?这些泛型不应该是类型安全的还是与JSF有关的类型擦除会导致整个类型的安全问题?
也不应的返回值h:selectManyCheckbox是List<Role>,像我通过传递f:selectItems?

java generics jsf classcastexception type-safety

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

在Struts 2中获取拦截器参数

我有以下动作映射

<action name="theAction" ...>
...
    <param name="param1">one</param>
    <param name="param2">two</param>
    ...
    <param name="paramN">nth-number</param>
...
</action>
Run Code Online (Sandbox Code Playgroud)

我可以在Interceptor中使用以下行获取参数映射

Map<String, Object> params = ActionContext.getContext().getParameters();
Run Code Online (Sandbox Code Playgroud)

如上所述,是否有任何方法可以获得以下映射中定义的拦截器参数.

<action name="theAction" ...>
...
    <interceptor-ref name="theInterceptor">
        <param name="param1">one</param>
        <param name="param2">two</param>
        ...
        <param name="paramN">nth-number</param>
    </interceptor-ref>
...
</action>
Run Code Online (Sandbox Code Playgroud)

并且动作参数以下列方式定义,动作参数和拦截器参数应该可以单独访问.

<action name="theAction" ...>
...
    <param name="param1">one</param>
    <param name="param2">two</param>
    ...
    <param name="paramN">nth-number</param>
    ....
    <interceptor-ref name="theInterceptor">
        <param name="param1">one</param>
        <param name="param2">two</param>
        ...
        <param name="paramN">nth-number</param>
    </interceptor-ref>
...
</action>
Run Code Online (Sandbox Code Playgroud)

请注意,我不想在拦截器中声明参数字段

//all fields with their getters and setters
private String param1;
private String param2; …
Run Code Online (Sandbox Code Playgroud)

java parameters struts2 interceptor interceptorstack

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

未使用的私有方法、私有字段和局部变量

我们正在使用声纳来审查我们的代码库。未使用的私有方法、未使用的私有字段和未使用的局部变量的违规情况很少。

根据我的理解,私有方法和私有字段只能通过反射和 Java 本机接口在类外部访问。我们没有在代码库中使用 JNI,而是在某些地方使用反射。

所以我们计划是workspace对这些方法和字段进行完整的搜索,如果即使通过反射也没有在任何地方使用它们,那么这些将被注释掉。再次通过反射访问私有方法和字段的机会非常少。这是为了更安全的一面。

不能在方法之外访问未使用的局部变量。所以我们可以注释掉这些。

您对此还有其他建议吗?

java sonarqube

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

Struts 2.3.14 junit测试

我正在使用Struts 2.3.14作为我的应用程序...我需要在我的应用程序中进行一些单元测试...所以我使用的是junit4 ...但是当我ActionProxy在我的测试中使用时,它会显示NullPointerException...

我的测试代码是:

ActionProxy proxy=getActionProxy("/customize/saveRewards");
    SaveRewardsPlus rewards=(SaveRewardsPlus)proxy.getAction();
    request.setParameter("list[0].img_id", "1");        
    request.setParameter("list[0].tag", "Test Tag");
    request.setParameter("list[0].desc", "Test Desc");        
    String result=proxy.execute();        
    assertEquals("success", result);  
Run Code Online (Sandbox Code Playgroud)

我的行动班是:

private List<RewardsBean> list;    

public String execute() {
    try {
        Class.forName(DRIVER);
        con = DriverManager.getConnection(CONSTR, USER, PWD);
        for (RewardsBean rb : list) {
            sql = "update rewards set tag=?,description=? where img_id=?";
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, rb.getTag());
            ps.setString(2, rb.getDesc());
            ps.setInt(3, rb.getImg_id());
            ps.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return …
Run Code Online (Sandbox Code Playgroud)

java struts2 junit4 struts2-junit-plugin

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

如何使用Struts 2在jsp中获取动作URL

我有网址:http: //demo.lendingclub.com/account/summary.action.当访问这个url时,它将首先进入拦截器类中的authenticate拦截器,如果我使用:

String uri = req.getRequestURI();
Run Code Online (Sandbox Code Playgroud)

它会回来 /account/summary.action

但是如果我在jsp中使用它:

<%
    HttpServletRequest req = ServletActionContext.getRequest();
    String uri = req.getRequestURI();
%>
Run Code Online (Sandbox Code Playgroud)

它将返回: /mainapp/pages/account/summary.jsp

为什么它们不同,我如何在JSP中获取操作URL?

java jsp struts2 request

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

在后台查看Play商店以确定是否可以在设备上下载应用程序

我知道我可以使用URL链接到Play商店:

market://details?id=com.example.appname
Run Code Online (Sandbox Code Playgroud)

我想做的是在后台"ping"此URL,并确定该应用程序是否实际可用,然后,我可以根据需要修改我的UI.

android google-play

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

如何冻结HashMap以防止进一步的更改?

这个问题几乎是不言自明的.我有一个数据结构(我提到了一个HashMap但也可能是一个Set或一个List),我最初填充:

Map<String, String> map = new HashMap<String, String>();

for( something ) {
  map.put( something );
}
Run Code Online (Sandbox Code Playgroud)

填充结构后,我永远不想添加或删除任何项目:

map.freeze();
Run Code Online (Sandbox Code Playgroud)

如何使用标准Java库实现这一目标?

java data-structures

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