• Post Reply Bookmark Topic Watch Topic
  • New Topic

a simple JSP problem

 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a jsp page Test.jsp





This file i have saved in the c:/sun/SunWebserver6.1/docs/project/Test.jsp folder.


now i want to import a class(this class is already compiled and is in the c:/sun/SunWebserver6.1/docs/project/WEB-INF/classes folder ) into my Test.jsp file .

i am confused what should i write in my page import statement in the JSP page .

should i write




Q1. plz look at my dir structure of files and tell me whether my importing statement is correct ?


Q2. At the time of creating the class should i write (is it necessary ?) at the top " package project.WEB-INF.classes; " ? otherwise i can write the simple java file and then compile and then put the class file into the classes folder . which one is correct ?


plz can anybody help ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"salvador rc",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any answer ?
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your import statement should reflect the package your class is in. For example, I have a package called "concertdemo". My import statement looks like this:

<%@ page language="java" import="concertdemo.*" %>

I have a "concertdemo" directory within the "WEB-INF\classes" directory. I don't need to specify "WEB-INF\classes" in the import statement.
 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look i have made a WEB-INF by my own...it is not the default one.

and i have a customized directory in that WEB-INF as shown above.


so what exactly should i write ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you download the authentic real JSP API docs for JSP from this SUN site. That way you can answer this question about the <@page tag, and many more, for yourself.
Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"salvador rcn", please actually read the naming policy and adjust your display name to match it. Be aware that accounts with invalid display names are subject to removal.

bear
Forum Bartender
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your class file begins with the statement:

package project;

you need to make another directory named "project" within WEB-INF/classes and put the class file in that (I know it seems redundant, but it is necessary). Then your import statement will be:

<%@ page language="java" import="project.*" %>

or

<%@ page language="java" import="project.MyClassName" %>

If your class is not part if any package, you may be able to put the class into the WEB-INF/classes directory and use the following import statement:

<%@ page language="java" import="MyClassName" %>

I've never tried to use a class that was not part of a package in this situation though, so I don't know if it will work.

Honestly, as Bill suggested, you can find these basics in the Sun documentation or a good JSP book. There are several good book recommendations here in the Bunkhouse.

Good luck.
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot to include that you need to adjust your CLASSPATH. That's another thing you can find in basic documentation/books if you need help with it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!