gpt4 book ai didi

java - 对警告 "Cannot resolve variable"感到困惑

转载 作者:行者123 更新时间:2023-12-02 01:31:35 26 4
gpt4 key购买 nike

login.java中我使用req.setAttribute("username", req.getParameter("username"));welcome.jsp 我正在使用 Hello ${username} 但 Intellij 给了我警告:

Cannot resolve variable 'username'

该变量有效。为什么我会收到此警告?

login.java

package ch.yourclick.zt;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class Login extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("username", req.getParameter("username"));
req.setAttribute("password", req.getParameter("password"));
req.getRequestDispatcher("/welcome.jsp").forward(req, resp);
}
}

最佳答案

您有 2 个选择:

选项 1

<% String username = (String) request.getAttribute("username"); %>
<%= username %>

选项 2

${requestScope.username}

关于java - 对警告 "Cannot resolve variable"感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55986622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com