无法在JSP中解析方法getParameter() [英] Cannot resolve method getParameter() in JSP
问题描述
我正在用JSP构建一个小项目.我想从HTML注册表单中获取数据并将其保存到数据库中.但是由于标题错误,我的IDE(intellij)不允许我这样做.有人知道解决办法吗?互联网研究并没有真正帮助我.
I'm building a small project in JSP. I want to take data from a HTML sign up form and save them to a database. But my IDE (intellij) won't allow me to do so because of the error in the title. Does anyone know a fix to this? Internet research didn't really helped me.
提前谢谢!
编辑
<%
String name = request.getParameter("realName");
%>
错误:无法解析方法'getParameter(java.lang.String)'.
Error: Cannot resolve method 'getParameter(java.lang.String)'.
推荐答案
我假设您的JSP文件如下所示:
I'm assuming that your JSP file looks like this:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
String name = request.getParameter("realName");
%>
Here's the param "realName": <%=name%>
</body>
</html>
看起来像这样,在您的IntelliJ中:
And that it looks like this, in your IntelliJ:
如果是这种情况,我几乎可以肯定您在类路径中缺少了servlet-api.jar
文件.
If that's the case, I'm almost sure you're missing the servlet-api.jar
file in your classpath.
以下是在IntelliJ上添加它的方法之一:
Here's one of the ways to add it on IntelliJ:
- 右键单击您的项目,然后选择打开模块设置:
- 确保您位于模块部分的依赖项标签上,单击底部的"+"按钮,然后选择 1个JAR或目录... :
- Make sure that you're on the Modules section, Dependencies tab, click on the "+" button at the bottom, and select 1 JARs or directories...:
- 从(这很重要:)的文件夹
lib
中选择文件servlet-api.jar
.要在其中部署应用程序的容器(在我的情况下是 apache-tomcat- 8.5.31 ):
- Select the file
servlet-api.jar
from the folderlib
at (THIS IS IMPORTANT:) the container where you're deploying your application (in my case, apache-tomcat-8.5.31):
- 然后单击确定"按钮.您的程序现在应如下所示:
您很高兴!
希望对您有帮助.
注意:我知道有时候您无法避免使用scriptlet,尤其是当您处理旧版代码时,就像我有一段时间一样.即使如此,也请注意此处有关使用脚本的其他答案.还有其他几个选项.
这篇关于无法在JSP中解析方法getParameter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!