我有一个jsp页面和一个类。我正在尝试在 jsp 页面中使用类的信息。这是代码:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="user.Customer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<h1>Main Menu</h1>
<% session.setAttribute("username", Globals.customer.getUsername());
session.setAttribute("password", Globals.customer.getPassword());
session.setAttribute("name", Globals.customer.getName());
session.setAttribute("surname", Globals.customer.getSurname());
session.setAttribute("phone", Globals.customer.getPhone());
session.setAttribute("address", Globals.customer.getAddress());
session.setAttribute("email", Globals.customer.getEmail());%>
<a href="editinfo.jsp">Edit your personal information</a>
</body>
</html>
全局类:
import user.Customer;
public class Globals {
public static Customer customer;
}
客户等级:
package user;
public class Customer {
public Customer(){}
public Customer(String username,String password,String name,String surname,String phone,String address,String email){
this.username=username;
this.password=password;
this.name=name;
this.surname=surname;
this.phone=phone;
this.address=address;
this.email=email;
}
private String username;
private String password;
private String name;
private String surname;
private String phone;
private String address;
private String email;
public String getName(){
return name;
}
public String getSurname(){
return surname;
}
public String getUsername(){
return username;
}
public String getPassword(){
return password;
}
public String getEmail(){
return email;
}
public String getPhone(){
return phone;
}
public String getAddress(){
return address;
}
}
这就是我所做的:当用户登录时,我首先通过设置其用户名、电子邮件等来创建一个客户对象,然后将其添加到当前会话中。但在一线
session.setAttribute("username", Globals.customer.getUsername()
它给出了一个错误说
An error occurred at line: 14 in the jsp file: /main.jsp
Globals cannot be resolved
11: <body>
12:
13: <h1>Main Menu</h1>
14: <% session.setAttribute("username", Globals.customer.getUsername());
15: session.setAttribute("password", Globals.customer.getPassword());
16: session.setAttribute("name", Globals.customer.getName());
17: session.setAttribute("surname", Globals.customer.getSurname());
谁能帮我这个?谢谢