Disregard all other files but RandomList.jsp
and RanUtilities.java
.
This one is RandomList.jsp
. coreservlets
returns errors saying 'coreservlets cannot be resolved'. This made me try make a directory coreservlets
in WebContent
directory and put a .class file in it.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Random List (Version 1)</TITLE>
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<H1>Random List (Version 1)</H1>
<UL>
<%
int numEntries = coreservlets.RanUtilities.randomInt(15);//here
for(int i=0; i<numEntries; i++) {
out.println("<LI>" + coreservlets.RanUtilities.randomInt(10));// and here
}
%>
</UL>
</BODY>
</HTML>
Also, RanUtilities.java
has package coreservlets;
in the first line. There's no error on java syntax in both files.
package coreservlets;
public class RanUtilities {
public static int randomInt(int range) {
return(1 + ((int)(Math.random() * range)));}
public static void main(String[] args) {
int range = 10;
try {
range = Integer.parseInt(args[0]);}
catch(Exception e) { // Array index or number format}
for(int i=0; i<100; i++) {
System.out.println(randomInt(range));}}}
This is a result when I ran RandomList.jsp
.
I thought making a new directory with name coreservlets
and putting the file would be okay(of course I tried putting .java file too). And I also tried the same thing into WEB-INF
folder as well.
What directory do I have to place the .class or .java folder?
Servlet文件应位于src>包>类> .java中
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.