虽然我已经在我的Driver类中拥有了属性电子邮件,但我仍然收到此错误。这是我的Driver类
package pack1;
import java.sql.*;
public class Driver {
private String name, email, password, contact;
private char gender;
public Driver()
{
name = "";
email = "";
password = "";
contact = "";
}
public void setDriverName(String name){
this.name = name;
}
public void setDriverGender(char gender){
this.gender=gender;
}
public void setDriverEmail(String email){
this.email = email;
}
public void setDriverPassword(String password){
this.password = password;
}
public void setDriverContact(String contact){
this.contact = contact;
}
public String getDriverName(){
return name;
}
public char getDriverGender(){
return gender;
}
public String getDriverEmail(){
return email;
}
public String getDriverPassword(){
return password;
}
public String getDriverContact(){
return contact;
}
public static boolean LoginDriver(String email, String password){
boolean validate = false;
try{
Connection con = DatabaseConnectionFactory.createConnection();
Statement st = con.createStatement();
PreparedStatement ps1 = con.prepareStatement("select * from driver where Email=? and Password=? ");
ps1.setString(3, email);
ps1.setString(4, password);
ResultSet rs1 = ps1.executeQuery();
validate = rs1.next();
con.close();
}
catch(Exception e){
e.printStackTrace();
}
return validate;
}
}
这是我的servlet的代码
package pack1;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Servlet6
*/
public class Servlet6 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Servlet6() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try{
Driver driver = new Driver();
driver.setDriverEmail(request.getParameter("email"));
driver.setDriverPassword(request.getParameter("password"));
if(Driver.LoginDriver(request.getParameter("email"), request.getParameter("password")))
{
Driver dr = new Driver();
dr.setDriverEmail(String.valueOf(request.getParameter("email")));
dr.getDriverEmail();
HttpSession sessionDriver = request.getSession();
sessionDriver.setAttribute("email", dr.getDriverEmail());
RequestDispatcher rd = request.getRequestDispatcher("DriverInfo.jsp");
rd.forward(request, response);
}
else
{
RequestDispatcher rd3 = request.getRequestDispatcher("LoginFail.html");
rd3.forward(request, response);
}
} finally {}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
最后这是我的jsp页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="pack1.Driver"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>AIRA Carpool</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="main style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<center><img src = "aira.jpg" class = "companySize"/></center>
<nav>
<ul id="menu">
<li><a href="main.html">HOME</a></li>
<li><a href="Login.jsp">LOGIN</a>
<li><a href="form.html">JOIN</a></li>
<li><a id="find">FIND</a></li>
<li><a href="contactUs.html">CONTACT US</a></li>
<li><a href="Rate.html">RATE US</a>
</ul>
</nav>
<jsp:useBean id = "driver" scope = "request" class = "pack1.Driver"></jsp:useBean>
<br><br>
<fieldset>
<legend>Login</legend>
<div class ="row">
<div class="input-field col s6">
<form action = "Servlet6" method = "POST">
<input type = "email" id = "email" name = "email" value="<jsp:getProperty name="driver" property="email"/>">
<label for = "email">Email</label>
</div></div>
<div class ="row">
<div class="input-field col s6">
<input type = "password" id = "password" name = "password" value="<jsp:getProperty name="driver" property="password"/>">
<label for = "password">Password</label>
<input type = "submit" class = "btn waves-effect waves-light" value = "Submit"/>
</form>
</div></div></fieldset>
</body>
</html>
如果有人有兴趣,这里是错误列表
org.apache.jasper.JasperException: Cannot find any information on property 'email' in a bean of type 'pack1.Driver'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:756)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1220)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1131)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
org.apache.jasper.compiler.Node$Root.accept(Node.java:471)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Generator.generate(Generator.java:3652)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:252)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我已经尝试过将属性名称放在小写中的解决方案,我真的不明白为什么它无法找到属性电子邮件,因为它显然在那里。必须有一些我无法看到的东西。我真的需要你的帮助。提前谢谢你
答案 0 :(得分:0)
您的财产名称为&#34; driverEmail&#34;因为:
public void setDriverEmail(String email){
this.email = email;
}
public String getDriverEmail(){
return email;
}
尝试将其更改为:
public void setEmail(String email){
this.email = email;
}
public String getEmail(){
return email;
}