小编Dun*_*nes的帖子

如何使用Apache Commons BeanUtils设置日期类型值,

我有一个HTML表单enctype="multipart/form-data"。我有一个dto它拥有所有类settergetters。由于我要以多部分形式提交表单,getParameter()因此无法使用我使用Apache Commons BeanUtils来处理html表单字段的方法。我的servlet如下

List<FileItem> items = (List<FileItem>) new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
String fieldname = item.getFieldName();
String fieldvalue = item.getString();
System.out.println(fieldname);
System.out.println(fieldvalue);
// ... (do your job here)
//getters and setters
try {if((!fieldname.equals("dob"))&&(!fieldname.equals("doj"))){
             BeanUtils.setProperty(teacherInfo, fieldname, fieldvalue);}
} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (InvocationTargetException e) {
    e.printStackTrace();
}

} else {

        //Code for …
Run Code Online (Sandbox Code Playgroud)

java servlets file-upload apache-commons-beanutils

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

for循环生成"1,4,9,16,25,36,49,64,81,100"

如何编写for循环来提供此输出?我在想一个嵌套循环?

for (int i = 0; i < 100; i++){
    for (int j = 0; j < i; j++) {
Run Code Online (Sandbox Code Playgroud)

但我不知道该怎么走?

谢谢

java loops for-loop

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

Get string in square brackets

I have a string: head1 [00100 - 00228]

I need to retrieve the value that is there is square bracket, i.e. 00100 - 00228

I have used:

String a="head1  [00100 - 00228]";    
replaceAll("(\\[.*?\\])", ""))
Run Code Online (Sandbox Code Playgroud)

but this has removed square bracket string. Can anyone help me to get the desire output?

java regex

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

将值附加到JTextField?

我想JTextField在Java中附加一个值.就像是:

String btn1="1"; 
textField.appendText(btn1);
Run Code Online (Sandbox Code Playgroud)

java swing jtextfield

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

按"?/"拆分不起作用

我想通过以下方式拆分字符串:"?/".我的字符串是:hello?/hi/hello.

我的代码是:

String [] list=myString.split("/?/");
Run Code Online (Sandbox Code Playgroud)

我的输出是:[HELLO,hi,hellow]但我希望看到:[hello,hi/hello].

我怎样才能做到这一点?

java regex split

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

在Java中将字符串拆分为子字符串

我有一个字符串,我想在Java中将其拆分为子字符串,原来字符串是这样的

Node( <http://www.mooney.net/geo#wisconsin> )
Run Code Online (Sandbox Code Playgroud)

现在我想通过(#)将它拆分成子串,这是我的代码

String[] split = row.split("#");

String word = split[1].trim().substring(0, (split[1].length() -1));
Run Code Online (Sandbox Code Playgroud)

现在这段代码正在运行,但它给了我

    "wisconsin>"
Run Code Online (Sandbox Code Playgroud)

最后的工作我想要的只是工作"威斯康辛州"没有">"这个标志,如果有人有想法请帮助我,提前谢谢.

java string split substring

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

改进我的验证

当用户输入他们的ID我希望它具有特定格式时,他们大多在评论中解释.我想知道他们是否更容易更有效地这样做.另外,是否有办法将输入的字母更改为我完成代码的方式或任何其他方法.

private boolean setCustomerID(String id) {
    //Validates the customerID contains 3 letters a hypthen then 4 numbers
    if ((id.charAt(0) < 'A' || id.charAt(0) > 'Z')
            || (id.charAt(1) < 'A' || id.charAt(1) > 'Z')
            || (id.charAt(2) < 'A' || id.charAt(2) > 'Z')
            || (id.charAt(3) != '-')
            || !isDigit(id.charAt(4))
            || !isDigit(id.charAt(5))
            || !isDigit(id.charAt(6))
            || !isDigit(id.charAt(7))) {
        return false;
        //Checks the user enters P, B or C for first letter
    } else if ((id.charAt(0) == 'P' || id.charAt(0) == 'B' || id.charAt(0) == …
Run Code Online (Sandbox Code Playgroud)

java validation performance

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

打印没有重复的ArrayList元素

我有一个ArrayList重复的数字:

1
2
3
1
2
4
Run Code Online (Sandbox Code Playgroud)

我想要做的是打印程序1,2,3,4并忽略已经打印的整数.

我通常采用的方法是使用for循环遍历ArrayList,但我正在努力阻止元素重复.我在想某种计数器系统可能在这里工作,但我不确定实现它,所以任何帮助将不胜感激.

java arraylist duplicates

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

使用contains方法

该程序的目标是获取两个数组x和y,然后创建和数组列表包含在x和y中出现的数字,然后打印出这个匹配数字的数组.当我去编译时,它给了我第19行预期的错误类和另一个错误说";" 预期在同一条线上,我猜是由于另一个错误.这只是该行的错误还是更大的问题?

import java.util.ArrayList;
import java.util.Arrays;
public class FindCommon {

    public static void main (String[] args) {

        ArrayList list = new ArrayList();



        int[] x = {1, 4, 3, 0, 1, 2};
        int[] y = {6, 4, 5, 0, 6, 1};


        for (int i = 0; i < x.length ; i++){

            int number = x[i];

            if (y[].(contains(x[i])){   // Line 19

                list.add(x[i]);        
            }

            System.out.println(list);

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java arrays contains arraylist

-3
推荐指数
1
解决办法
81
查看次数

帐户余额计算错误

运行以下代码的结果是:

Final account balance is: -97.0
Run Code Online (Sandbox Code Playgroud)

但答案应该是150.0,对吗?我哪里出错了?

class Account
{
  double initBalance;

  Account(double initBalance)
  {
    initBalance=this.initBalance;
  }

  double getBalance()
  {
    return initBalance;
  }

  void deposit(double amt)
  {
    initBalance=initBalance + amt;
  }

  void withdraw(double amt)
  {
    initBalance=initBalance - amt;
  }

}


class TestAccount
{
  public static void main(String args[])
  {
    Account acct=new Account(100);
    acct.deposit(50);
    System.out.println("Final account balance is: " +acct.getBalance());
  }
}
Run Code Online (Sandbox Code Playgroud)

java

-4
推荐指数
1
解决办法
183
查看次数