Cannot find any information on property 'User' in a bean of type 'com.entity.user'

故障码:

严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Cannot find any information on property 'User' in a bean of type 'com.entity.user'
	at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
	at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1117)
	at org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1124)
	at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
	at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
	at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
	at org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
	at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
	at org.apache.jasper.compiler.Generator.generate(Generator.java:3426)
	at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:216)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
	at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

故障的起因是这样的:


没故障的源代码:

user.java源代码:

package com.entity;

public class user {
	
	private String user="zhangsan";

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}
	
}

index.jsp源代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
    
    
    My JSP 'index.jsp' starting page
	
	
	    
	
	
	
  
  
  
  
  
这里是JavaBean取值


这里是Java取值
<%=us.getUser() %>


运行的结果:

Cannot find any information on property 'User' in a bean of type 'com.entity.user'_第1张图片


当我们将实体类user.java中的属性user改成User时,此时再get/set

更改过后的user.java源代码:

package com.entity;

public class user {
	
	private String User="zhangsan";

	public String getUser() {
		return User;
	}

	public void setUser(String user) {
		User = user;
	}
	
}

此时很多人习惯于将index.jsp页面也做相应的更改,即也将user改成User,此时的运行结果是:

Cannot find any information on property 'User' in a bean of type 'com.entity.user'_第2张图片


        其实正确的解决办法是index.jsp页面什么也不需要动,因为user.java虽然将属性user变成User,但是其实属性的get/set方法仍然是不变的,也就是说只要是get/set方法不变,无论是user还是User,在前台jsp页面来看其实都是一样的,所以说前台页面不需要任何改变。


        当然如果说用jsp页面内嵌Java代码的方式来取值就不会出现这种问题了(即采用<%=us.getUser()%>的方式),因为此时的取值方式是系统提示生成的,此时就会避免这种问题的发生。




你可能感兴趣的:(其他,JavaBean)