小编sun*_*leo的帖子

使用BeanUtils设置setter值

我尝试使用setter设置值但是null来了.请帮助我,并给出一些其他更好的方法来做.

import org.apache.commons.beanutils.BeanUtils;

public class TestSetter {

    public static void main(String args[]) throws Exception
    {
        Test t = new Test();
        BeanUtils.setProperty(t,"te","teval");
        System.out.println("tevalue :"+t.getTe());
    }
}
class Test
{
    String te;

    public String getTe() {
        return te;
    }

    public void setTe(String te) {
        this.te = te;
    }

}
Run Code Online (Sandbox Code Playgroud)

例外:

Exception in thread "main" java.lang.reflect.InvocationTargetException: Cannot set te
    at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1025)
    at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:313)
    at test.reflection.TestSetter.main(TestSetter.java:10)
Caused by: java.lang.NoSuchMethodException: Property 'te' has no setter method
    at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1746)
    at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
    at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
    at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
    ... …
Run Code Online (Sandbox Code Playgroud)

java reflection apache-commons-beanutils

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

JSP和Servlet setAttribute

我的问题很简单,但我很困惑,请帮助我.

在JSP中,我从Servlet1接收一个Attribute(idsList),我想将此Attribute(idsList)发送到另一个servlet,Servlet2,但我可以使用session.setAttribute().我的麻烦是,我们如何在JSP本身发送给Servlet2?

这是我的代码,但它不起作用,因为相同的请求用于设置和获取.请帮忙.

在Servlet1中:

request.setAttribute("idsList",idsList);---is null
Run Code Online (Sandbox Code Playgroud)

在JSP中

List<Integer> idsList =(List<Integer>)request.getAttribute("idsList");
System.out.println("size of ids list :"+idsList.size());
request.setAttribute("idsList",idsList);
Run Code Online (Sandbox Code Playgroud)

在Servlet2中:

request.getAttribute("idsList");---is null
Run Code Online (Sandbox Code Playgroud)

java jsp servlets

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

如何使用String中的固定整数和十进制值检查十进制数字

请帮助我找到有效的方法来查找数字字符串.

String str ="-100000.000";
System.out.println(str.matches("-?\\d+(\\.\\d+)?"));
Run Code Online (Sandbox Code Playgroud)

它工作得很完美,但我想接受像这样的数字字符串

String length must be maximum (10,3)--- Example 1234567890.999
String length must be minmum   (1)------0
Numeric String must be positive.

valid Numeric Strings(2.333    1878.12    787          989.0)
Run Code Online (Sandbox Code Playgroud)

java regex

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

如何与Where in子句中的Case进行比较

这里有人员和地址表.有些人可能有地址.如果他们有地址则需要加入地址表,否则无需加入.请帮助解决此案.

select p.name,nvl(a.address,'address not available') from person p,address a
where p.id = 2 and case
            when p.addid is not null
              then   p.addid = a.id
             else 0=0 end   
Run Code Online (Sandbox Code Playgroud)

sql oracle

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

yyyyMMdd中1900-9999的Java正则表达式日期验证

如何从转换正则表达式

^((19|20)\\d\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])? for 1900-2099
Run Code Online (Sandbox Code Playgroud)

上面的一个完美地工作,只需要更改日期格式1900-9999。所以选择下面的一个。

我这样尝试过

^(([19-99])\\d\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])? for 1900-9999
Run Code Online (Sandbox Code Playgroud)

有什么问题,请引导我解决。

java regex

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

带有字符的Font Awesome Icon

我想在其上添加带有字符的超赞字体,但这样做失败。请帮助了解发生了什么问题。

输出:

在此处输入图片说明

尝试过的代码:

<i class="fa fa-square fa-2x" style="color:red;"><span style="text-color:white;">S</span></i>
<i class="fa fa-square fa-2x" style="color:yellow;"><span style="text-color:white;">XL</span></i>                                           
<i class="fa fa-square fa-2x" style="color:green;"><span style="text-color:white;">XXL</span></i>
Run Code Online (Sandbox Code Playgroud)

css font-awesome

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

如何使用java流将列表转换为具有多个键和值的映射作为列表

我有 ssns 列表Users(id,ssn,name)和 ids 列表的列表,需要转换为 ssns 列表和 id 列表的映射。你能帮忙解决这个问题吗?

List.of(new User(1, "ssn1", "user1"), new User(2, "ssn2", "user2"), new User(3, "ssn3", "user3"))
Run Code Online (Sandbox Code Playgroud)
Map with 2 keys("SSNs","IDs") and list as value
"SSNs" -  List("ssn1","ssn2","ssn3")
"IDs" -  List(1,2,3)
Run Code Online (Sandbox Code Playgroud)

代码

public class Test {

    public static void main(String[] args) {

        List<User> users = List.of(new User(1, "ssn1", "user1"), new User(2, "ssn2", "user2"),
                new User(3, "ssn3", "user3"));

        Map<String, List<Object>> userMap = users.stream().collect(Collectors.groupingBy(User::getSsn));
    
    }

}

class User {
    public int getId() {
        return id;
    } …
Run Code Online (Sandbox Code Playgroud)

java java-stream

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

如何在html中获取url,document.referrer为空

请帮助获取调用此页面的当前URL?这有什么问题?,因为警报空洞.

<html>
<head>
<script>
 function check()
{
alert(document.referrer);
}
</script>
</head>
<body onload="check()">

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript

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