简体   繁体   中英

Can't import Java Class inside JSP

This is my project's structure in NetBeans

Project's Structure

I am trying to import the User.java file like that

<%@page import="User"%>

so then i can use it like that

<%
User user = (User) session.getAttribute("currentUser");
if (user == null) {
    response.sendRedirect("login_page.jsp");
}   
%>

This file is inside src folder but without a package name. I tried to use import="package.User" but that doesn't seem to work either.

Does anybody knows what is wrong with my structure? Thank you.

You can't import classes from the default package. You'll have to put your classes in packages and import them with their fully qualified name: packagename.classname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM