jquery - 如何在 JSP 中获取输入值?
问题描述
我有一个 JSP 页面需要读取 a 中的输入值if
,我尝试使用 Jquery 但不起作用。
<%-- my input with the year value --%>
<input type="text" id="year" value="2021">
<%-- my JSP page need test if year is bigger then 2019 --%>
<c:if test="${ $("#year") > 2019 }">
...
</c:if>
欢迎任何帮助。
解决方案
我可以通过 3 个步骤解决这个问题:
首先,我在 ajax 参数中发送输入的值
year : $("#year").val()
在我收到 Servlet 中的值之后
String year_value = request.getParameter("year");
并设置一个属性来获取 JSP 页面中的值。
request.setAttribute("year_value", Integer.parseInt(year_value));
在 JSP 页面中,我使用变量year_value
进行比较if
。
<c:if test="${ year_value > 2019 }">
...
</c:if>
推荐阅读
- java - 将程序集合操作转换为 java 流或反应流
- r - 基于边权重和图连通性的子图提取
- c# - BindAttribute 似乎在 ASP.Net MVC Core (2.0.8) 中不起作用
- c++ - 在 C++ 程序中使用 C 库中定义的类型,具有类似方案的命名空间
- unity3d - ARCore Unity Google Cardboard 支持
- javascript - 当 centerMode 为真且无限为假时,Slick.js 删除第一张和最后一张幻灯片上的间隙
- android - Android 模拟器无法启动。屏幕只是黑色/透视
- java - Pebble 模板继承失败且没有错误
- redux - 如何在 saga 中使用 redux 操作关闭 eventSource?
- python - 根据列表中包含的排除值从 Pandas 数据框中删除值