我正在使用 Tomcat 编写一个网络服务器。
我决定使用的技术是 JSTL。
我想先说好用,页面显示成功,一切运行 .
我喜欢摆脱警告。
我从intelliJ 得到的警告是:“无法解析变量''”,它来自我有一些JSTL 代码的JSP 页面。 jsp 页面是使用 RequestDispatcher forward 函数从我的 Controller 调用的。
request.setAttribute("resultsModel", resultsModel);
request.setAttribute("times", times);
request.setAttribute("emailErr", emailErr);
request.setAttribute("qid", id);
RequestDispatcher view = request.getRequestDispatcher("ShowResults.jsp");
view.forward(request, respone);
然后 JSP 页面在各种 JSTL 标记中使用此变量,例如来自页面:
<c:choose>
<%-- When database access was succesfull --%>
<c:when test="${resultsModel != null}">
<c:choose>
<%-- When the job ID exists --%>
<c:when test="${resultsModel.jobEntity != null}">
等等...
然后在我尝试访问 resultModel 的位置上发出警告。
我尝试添加一个 jsp:useBean 标记,如下所示:
<jsp:useBean id="resultsModel" scope="request" type="bgu.bioinf.rnaSequenceSniffer.Model.ResultsModel"/>
但我仍然收到警告。
任何的想法?我做错了什么?
谢谢!
最佳答案
我也遇到这个问题,真的很困扰我。
今天我用谷歌搜索了这个问题并没有找到解决方案。
但是我使用了 ModelMap
而不是 HttpServletRequest
.
map.put("info",info);
毫无疑问我收到了这个警告,然后我改变了方法:
map.addAttribute("info",info);
我想说这种方式确实解决了警告,你甚至可以
ctrl
+ button1
在 Controller 中导航 bean。我不知道这是否解决了其他场景中的问题,但在 intellij 2018.1 中我只是摆脱了它。希望它对你有用
关于jsp - JSTL 上的 IntelliJ 警告 "cannot resolve variable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27473478/