Java 为什么我会得到org.apache.jasper.jaspereException?
当我运行以下servlet时:Java 为什么我会得到org.apache.jasper.jaspereException?,java,jsp,jakarta-ee,servlets,Java,Jsp,Jakarta Ee,Servlets,当我运行以下servlet时: import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; public class Controller extends HttpServlet { @Override public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,Se
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
public class Controller extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
Bean bean = new Bean();
bean.setName("Suhail Gupta");
request.setAttribute("Name", bean);
RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
}
例外情况:
HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: PWC6054: Cannot find any information on property 'Name' in a bean of type 'Bean'
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs.
是生成的。我不明白为什么会这样
下面是Bean类:
这是index.jsp
页面:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="name" class="Bean" scope="request" />
Person created by the Servlet : <jsp:getProperty name="name" property="Name" />
</body>
</html>
JSP页面
由Servlet创建的人员:
我无法找到异常的原因。- 属性应该是小写的
——这是由java约定和javabeans标准规定的私有字符串名
- 标记应该再次使用小写的
-javabeanproperty=“name”
- bean的名称不应该是
,这很容易混淆。将其设置为name
(最好是小写)nameBean
- 你们班应该有一个包。默认包会导致问题
- 您可以简单地使用EL:
将解析为正确的值,而不是${nameBean.name}
标记jsp:
Bean
中的成员和Controller
中的属性名称使用name
而不是name
。是!问题解决了。(问题集还包括默认的包!),但是我得到了null
,其中我期望由bean.setName(“Suhail Gupta”)
设置的名称。这可能是什么原因?
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="name" class="Bean" scope="request" />
Person created by the Servlet : <jsp:getProperty name="name" property="Name" />
</body>
</html>