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 in Java by anonymous
16 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 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
457 views
0 votes
1 answer
+5 votes
3 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,380 points

edited Nov 6, 2018 by Omkar 5,551 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
55 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,520 points
617 views
0 votes
1 answer

Get parameters from the URL with JSP

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

answered May 28, 2018 in Java by parth295
• 4,600 points
355 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,840 points
60 views
0 votes
1 answer

Difference between JSF, Servlet and JSP?

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

answered Jul 2, 2018 in Java by samarth295
• 2,190 points
210 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 27, 2018 in Java by samarth295
• 2,190 points
52 views
0 votes
10 answers

How to import a jar file in Eclipse?

Go to your project right click and ...READ MORE

answered Dec 10, 2018 in Java by Hola77
26,710 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.