doPost() 方法中不熟悉的 Array 代码行
Unfamiliar Array line of code in doPost() method
下面的代码是servlet的doPost方法的代码,虽然不完整。如您所见,这是从网页获取参数的逻辑,即名字和姓氏以及出生日期。我确实理解 getparameter() 方法,但在第 5 行中,它是什么样的数组表示形式?我不习惯看到这种 Array 方法。我习惯的,或者到目前为止处理的是。
type[] arrayName = new type[length];
和
type[] arrayName;
arrayName = new type[length]
在第 5 行。为什么数组声明等于一些点运算符和一些方法。请解释一下,或者,如果有标签或主题名称,对于这种数组表示,请告诉我,我会尽快上课。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String firstName = request.getParameter("first-Name");
System.out.println("Firstname:" + firstName);
String lastname = request.getParameter("last-name");
String dob_raw = request.getParameter("dob");
String dobArray[] = dob_raw.split("\/");
String month = dobArray[0];
String day = dobArray[1];
String year = dobArray[2];
}
youtube link 到教程以备参考
https://www.youtube.com/watch?v=e7rSurdKrlk&index=14&list=PLTo_YL4Dk4Z_SxrG0XwbE1pGYyehh9gX3
我假设我们正在谈论这条线:
String dobArray[] = dob_raw.split("\/");
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with
the given expression and a limit argument of zero. Trailing empty
strings are therefore not included in the resulting array.
"\\/" 是一个正则表达式字符串。考虑到正则表达式实际上不是“\\/”而是“\/”,因为 java 字符串中的 \ 转义了取代它的字符。 "\/" 然后是 again 被正则表达式语言转义,所以一旦你排除了所有发生的转义,你真的只剩下 "/" 了。简而言之,将字符串分成几部分,其除数匹配一个 / 字符。这对于表示 URI 的字符串可能很方便,可能是文件路径,或者在本例中是日期。
我想如果您想知道在哪里可以了解更多信息,there is a straightforward tutorial 关于您可能会觉得有用的正则表达式。
字符串 class 方法 "split(String pattern)" 声明内存,它是实际的字符串数组。您在 String dobArray[] 中声明类型,它是字符串数组的句柄。
当你输入
对象 objectArray[] = new 对象[3];
你有一个对象数组的句柄 objectArray,由 'new Object[3]'
初始化
String 有一个名为 split() 的方法,它 returns 一个数组,我们所做的就是将该数组分配给变量 dobArray。
下面的代码是servlet的doPost方法的代码,虽然不完整。如您所见,这是从网页获取参数的逻辑,即名字和姓氏以及出生日期。我确实理解 getparameter() 方法,但在第 5 行中,它是什么样的数组表示形式?我不习惯看到这种 Array 方法。我习惯的,或者到目前为止处理的是。
type[] arrayName = new type[length];
和
type[] arrayName;
arrayName = new type[length]
在第 5 行。为什么数组声明等于一些点运算符和一些方法。请解释一下,或者,如果有标签或主题名称,对于这种数组表示,请告诉我,我会尽快上课。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String firstName = request.getParameter("first-Name");
System.out.println("Firstname:" + firstName);
String lastname = request.getParameter("last-name");
String dob_raw = request.getParameter("dob");
String dobArray[] = dob_raw.split("\/");
String month = dobArray[0];
String day = dobArray[1];
String year = dobArray[2];
}
youtube link 到教程以备参考 https://www.youtube.com/watch?v=e7rSurdKrlk&index=14&list=PLTo_YL4Dk4Z_SxrG0XwbE1pGYyehh9gX3
我假设我们正在谈论这条线:
String dobArray[] = dob_raw.split("\/");
Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
"\\/" 是一个正则表达式字符串。考虑到正则表达式实际上不是“\\/”而是“\/”,因为 java 字符串中的 \ 转义了取代它的字符。 "\/" 然后是 again 被正则表达式语言转义,所以一旦你排除了所有发生的转义,你真的只剩下 "/" 了。简而言之,将字符串分成几部分,其除数匹配一个 / 字符。这对于表示 URI 的字符串可能很方便,可能是文件路径,或者在本例中是日期。
我想如果您想知道在哪里可以了解更多信息,there is a straightforward tutorial 关于您可能会觉得有用的正则表达式。
字符串 class 方法 "split(String pattern)" 声明内存,它是实际的字符串数组。您在 String dobArray[] 中声明类型,它是字符串数组的句柄。
当你输入 对象 objectArray[] = new 对象[3]; 你有一个对象数组的句柄 objectArray,由 'new Object[3]'
初始化String 有一个名为 split() 的方法,它 returns 一个数组,我们所做的就是将该数组分配给变量 dobArray。