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
25 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 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
498 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 7,033 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
75 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,540 points
954 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
422 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,850 points
68 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
242 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
77 views
+1 vote
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
39,887 views