gpt4 book ai didi

java - 类无法在jsp页面解析

转载 作者:行者123 更新时间:2023-11-30 09:20:24 25 4
gpt4 key购买 nike

我有一个 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;
}


}

这就是我所做的:当用户登录时,我首先通过设置其用户名、电子邮件等创建一个 Customer 对象,然后将其添加到当前 session 中。但是在行中

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

<%@ page import="user.Customer" %>
<%@ page import="path.to.Globals" %>

或者,对两个导入使用单个页面指令

<%@ page import="user.Customer,path.to.Globals" %>

关于java - 类无法在jsp页面解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17419290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com