I have some JSP files that are included in other JSP files:
<%#include file="pages/contentXY.jsp"%>
This files should not be accessable for direct access.
So https://myUrl/pages/content/XY.jsp should not be accessable.
How can I achieve this?
In the same directory as my index.jsp, I have a folder called 132b.
Inside 132b I have a folder called classes which contains a bunch of Java files.
In my index.jsp, I have tried:
<%# page import="132b/classes/*" %>
<%# page import="132b.classes.*" %>
The first attempt complained about an unexpected end of comment.
The 2nd attempt couldn't find the class I was trying to instantiate so it couldn't be resolved to a type.
How do I properly import/include the classes I wrote?
By default it will search Java files inside src folder till you explicitly set it to be something else..
Try putting 132b folder inside src folder and see if <%# page import="132b.classes.*" %> works.
I always prefer to import only classes which are needed in that particular page instead of importing all the classes of a package.
I've seen topics like this alraedy, but its not working for me.
So I have a game that succesfully made into an applet and it has many classes that are in a package called Build9. I want to put it on my website.
My file structure is the html file in the root "Desktop/My Name" and I have a media folder that has the RomanFury.jar.
I've tried every combination of changing around the code and archive in the HTML tag. With the classic:
<applet code="Main" archive="RomanFury.jar" width="1280" height="720">
My game.
</applet>
I get an error that says it cannot find Main. If I put media/RomanFury.jar or put media/ infront of main the same kind of error is given.
Can someone tell me the correct html tag?
My .class files are in a folder called "Build9" in RomanFury.jar.
Based on the information provided, this
<applet code="Main" archive="RomanFury.jar" width="1280" height="720">
should be
<applet code="Build9.Main" archive="RomanFury.jar" width="1280" height="720">
because your game has many classes that are in a package called Build9 (and your .class files are in a folder called "Build9" in RomanFury.jar).
this is my first time trying to use java for backend web systems.
I have been reading up some guides on how to do this, and thus far i understand the following points:
I am not allowed to import .java files, but rather, import the class files.
<%# page language="java" import="somefile.*"%> this is how i import a package.
After importing a package, I am required to create an instance of the class.
However, I am confused with a few things.
I now have a Dynamic Web Project, developing in Eclipse IDE and using TomCat7.0 apache.
I have a directory
Java_Resources/src/somepackage/
and some .java files in the above directory.
Question 1, in Eclipse, when I run these files, they are automatically compiled. Where does these class files go?
Question 2, when I run the following code, I recieved some errors. What am I doing wrong? Is it because I do not have my class files in the right directory?
<%# page language="java" import="twitter.*"%>
<%
JavaFile jf = new Javafile();
String result = jf.searchTweets("someString");
System.out.println(result);
%>
Error report:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /hello.jsp at line 10
7: <%# page language="java" import="twitter.*"%>
8:
9: <%
10: Javafile jf = new JavaFile();
11:
12: String result = jf.searchTweets("someString");
13: System.out.println(result);
Thank you for your time and effort.
note: I have read the following links, but they do not seem to provide a solution on how to write your own .java files and import these classes into your jsp files.
http://www.jsptut.com/
How do you import classes in JSP?
http://www.coderanch.com/t/288534/JSP/java/importing-class-file-jsp
EDIT: I found my own answer.
This is my original directory
As you can see, my WEB-INF/lib is empty.
All that was required to do, is to move the relevant .jar files into this directory.
Note: I have already imported the relevant .jar files to the Eclipse project, but it seems that I need to move them into WEB-INF/lib on top of importing them into the project.
Thank you to all that helped answer my question.
This is my final directory image
Only classes may be imported into a .java file, and a JSP "compiles" to a .java file, so this requirement holds for JSP files too.
From a quick glance at the API, it seems that your import is formatted correctly; but, you are importing the wrong namespace. The javadoc for the twitter4j API indicates that you should be importing "twitter4j" namespaces, not "twitter" namespaces.
Question 1, in Eclipse, when I run these files, they are automatically compiled. Where does these class files go?
The class files go inside WEB-INF/classes directory.
Question 2, when I run the following code, I recieved some errors. What am I doing wrong? Is it because I do not have my class files in the right directory?
Perhaps you have forgotten to put twitterXXX.jar (or whatever it is called) into WEB-INF/lib directory.
i have created a java package in source packages in netbeans
i have a jsp file in a web folder
now i want to import this java package in jsp file but i am not getting my package name in import command
Import package,
<%# page language="java" import="yourpackage.subpackage.*,java.util.*" %>
or,
<%
yourpackage.subpackage.ClassName k=new yourpackage.subpackage.ClassName();
....
%>