为什么来自Checkboxes的字符串值在java中增加了+1?

时间:2018-03-03 18:18:34

标签: jsp servlets checkbox

我正在JSP / Servlet中开发一个Web应用程序,我在其中从复选框中获取值并将其放在会话中。 之后,我将在数据库中逐个添加此复选框值以及更多属性。

问题是从复选框中获取值后,字符串的长度会增加,正如您在stacktrace中看到的那样。 例如,如果String值为abc,则显示其长度为5。

如果我在这里做错了,请帮助我。

packageContext

This is what the error is, you can see that while printing query it is showing \n after the title.

Value abc is present in database also.

1 个答案:

答案 0 :(得分:0)

出于某种原因,您在txt <- '{"2017-12-07 13:07:00": {"1. open": "169.7800", "2. high": "169.9100", "3. low": "169.7800", "4. close": "169.8500", "5. volume": "20659"}, "2017-12-07 13:06:00": {"1. open": "169.7920", "2. high": "169.8300", "3. low": "169.7400", "4. close": "169.7700", "5. volume": "17485"}, "2017-12-07 13:05:00": {"1. open": "169.8600", "2. high": "169.8600", "3. low": "169.7350", "4. close": "169.7924", "5. volume": "19789"}, "2017-12-07 13:04:00": {"1. open": "169.8000", "2. high": "169.8800", "3. low": "169.7600", "4. close": "169.8600", "5. volume": "25589"}, "2017-12-07 13:03:00": {"1. open": "169.7800", "2. high": "169.8100", "3. low": "169.7100", "4. close": "169.8100", "5. volume": "19679"}, "2017-12-07 13:02:00": {"1. open": "169.9400", "2. high": "169.9400", "3. low": "169.7700", "4. close": "169.7799", "5. volume": "46347"}, "2017-12-07 13:01:00": {"1. open": "169.9540", "2. high": "170.0200", "3. low": "169.9400", "4. close": "169.9500", "5. volume": "66847"}, "2017-12-07 13:00:00": {"1. open": "169.9400", "2. high": "169.9439", "3. low": "169.9100", "4. close": "169.9400", "5. volume": "8546"}}' '\n'附加了标题中的项目。

更好地调试代码(添加一个sysout)并检查您在以下代码段中实际获得的内容

'\s+'

case 1: String[] checkbox = request.getParameterValues("c1"); if (checkbox != null) { System.out.println(checkbox); session.setAttribute("title", checkbox); } break; 是jsp上输入元素(复选框)的名称。这也应该在整个页面中是唯一的。

如果你在这里使用javascript更好用js来计算dom元素的值。