Should a class file always be inside package for importing it in jsp page

0 votes

I am new to Java and learning to work with JSP. I created a class inside student package, when I import it code worked successfully. But when I omitted the package and place the class "Student" directly in WEB-INF/classes folder, I got an error saying 

Student cannot be resolved to a type. 

I searched alot but did not find any reasonable answer. However, I solved the problem by putting this class inside package, but want to know that is this necessary that class should exist inside package. Thank You

May 24, 2019 in Java by anonymous
2,199 views

1 answer to this question.

0 votes

Hey there!

It is not necessary for the class to be inside the package if you have you mentioned to import the class in your JSP file. Example:

<%@ page import "com.example.Student" %>

But if you have not, then it is necessary for the class to be placed inside the package.

answered May 24, 2019 by Karan

Related Questions In Java

0 votes
1 answer

How can a war file be deployed in Tomcat 7?

You can access your application from: http://localhost:8080/sample Deploying ...READ MORE

answered Apr 20, 2018 in Java by sophia
• 1,400 points
2,083 views
0 votes
1 answer
0 votes
1 answer

Vanilla JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it

Use Internet Explorer 9 or later if you're using VANILLA pure JavaScript without jQuery. document.addEventListener("DOMContentLoaded", function(event) { // ...READ MORE

answered Nov 8, 2022 in Java by Damonlang
• 700 points
2,984 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,193 views
0 votes
1 answer

Importing classes in JSP

Use Page Directive to import a Class ...READ MORE

answered May 25, 2018 in Java by Rishabh
• 3,620 points
28,008 views
0 votes
1 answer

Get parameters from the URL with JSP

To delete the subject record with its ...READ MORE

answered May 29, 2018 in Java by Parth
• 4,640 points
3,384 views
0 votes
1 answer

How can we upload the files using JSP/ Servlets in Java?

<form action="upload" method="post" enctype="multipart/form-data"> ...READ MORE

answered Jun 8, 2018 in Java by Sushmita
• 6,920 points
871 views
0 votes
1 answer

Difference between JSF, Servlet and JSP?

Servlet - it's java server side layer. JSP ...READ MORE

answered Jul 3, 2018 in Java by samarth295
• 2,220 points
1,531 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
2,478 views
+5 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
359,640 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP