jsp 페이지와 클래스가 있습니다. 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());
이 사람이 나를 도와 줄 수 있다는 말을 주는가? 감사합니다
Globals 클래스의 패키지 선언은 어디에 있습니까? – Uooo
'글로벌 클래스'에 대한 코드 블록 및 사용법을 이해할 수 없습니다. 접근하려는 모든 메소드가 정의되어 있기 때문에'Customer class'의'instance'를 직접 사용하지 않는 것이 좋습니다. – Smit
나는이 문제를 해결해 주었다. – yrazlik