aspose file tools*
The moose likes Servlets and the fly likes compile????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "compile?????" Watch "compile?????" New topic
Author

compile?????

Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
hi...
i'm just started to learned servlet. we have a server where we place the tomcat server in there.i was assigned to build a web sites.all my folder is in the server.my question is..i have write a simple servlet and save it in the folder inside the server.how i want to compile those file?i've tried to browse the html file that call the servlet from my machine but it does not run the servlet.why this happen?
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
maybe you should at the path where the servlet.jar is installed


SCJP 1.4
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
i'm not clear enough.can u elaborate more.any examples...
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Hi suka,

I think you should go for some servlet tutorial, first.
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
Ok if you have Tomcat as your server try adding the {TOMCAT_DIR}/common/lib/servlet.jar in you classpath when you try to compile your servlets. maybe that your problem.

can you post your error messages here?
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
my machine is the client machine.tomcat had been installed in another machine where my file is in there and i'm sharing that file
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
You write
..i have write a simple servlet and save it in the folder inside the server.how i want to compile those file?i've tried to browse the html file that call the servlet from my machine but it does not run the servlet.why this happen? ...

So, my question is : were you able to compile the servlet or did you try to call the servlet before compiling it. Your question "how i want to compile those file" makes it very blurry.
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
actually, my machine is the client machine.tomcat had been installed in another machine(server) where my file(servlet and html) is in there and i'm sharing that file.i try to compile those servlet(actually those servlet will be call from the html) from my machine but its fail.

below is the html source code:

<HTML>
<head><title>Random numbers page</title></head>
<body bgcolor="white">
<h1>Random numbers page</h1>
<p>This site will let you pick some random numbers for any purpose</P>
<form method=post action="/classes/IntsServlet">
<h4>How many numbers do you want today?<h4>
<input name=howmany size=2> (default is 5)
<br>
<input type="submit" value="Get YOURS!">
</form>
</body>
</html>

and below is the servlet source code :

import java.io.*;
import java.util.Random;
import javax.servlet.*;
import javax.servlet.http.*;

public class IntsServlet extends HttpServlet{
protected final int DEFAULT_NUMBER=5;
public void doPost(HttpServletRequest req, HttpServletResponse resp)throws IOException {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();

out.println("<html>");
out.println("<head>");
out.println("<body bgcolor=\"white\">");

out.println("<title>Your personal random numbers</title>");
out.println("<h1>Your personal random numbers</h2>");
out.println("<p>Here are your personal random numbers, ");
out.println("carefully selected by a");
out.println("<a href=\"http://java.sun.com\">Java</a>program.");
out.println("<ol>");

int n=DEFAULT NUMBER;
String num=req.getParameter("howmany");
if(num !=null && num.length() !=0){
try{
n=Integer.parseInt(num);
}catch(NumberFormatException e){
out.println("<p>I didnt't think much of");
out.println(num);
out.println("as a number.</p>");
}
}

Random r=new Random();
for(int i=0;i<n; i++){
out.println("<li>");
out.println(r.nextInt(49));
out.println("</ol>");
out.println("<hr></hr>");
out.println("<a href=\"index.try.html\">back to main page</a>");
}
}
Bindesh Vij
Greenhorn

Joined: Oct 27, 2004
Posts: 23
All the files (including html files) should be there in the server where Tomcat is installed. The file heirarchy should follow the J2ee web module specification. You have to compile the servlet in the server itself. and put in the classes folder . You cannot just simply share the file and call it from the other like typical file sharing. It has to be called with

http://[specify-server-your-server-ip]:[port-at-which-tomcat-is-listening]/
[Web-folder]/[file-name.html]



Download this tutorial and get more knowledge on how to configure the Tomcat for web deployment..
JSP& Servlet book
[ October 31, 2004: Message edited by: Bindesh Vij ]
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
You could compile your servlet on the server machine. But personally, I think it's much easier that you compile your servlet on your client machine. That way, you are sure you've got a .class files which actually works. Consider your client as the development environment. As soon as your web application can work locally, you can upload it to the server.
So, one advice : donwload Tomcat and install it on your client.
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
my servlet is still in .java files.so, i need to compile it so that i can get the .class file and put in the server, right?now, i have tomcat in my machine.so, now i tried so many times to compile the .java file but it keeps giving me the same error...that is..

javax.servlet.*; does not exist
javax.servlet..http*; does not exist

i search from the internet on how to solve this problem.. the idea is i need to set the classpath but i'm not sure whether my setting is right or wrong.

my tomcat is in the directory

c:\program files\apache group\tomcat 4.1

how to solve this problem.plzzzzzzzz
Bindesh Vij
Greenhorn

Joined: Oct 27, 2004
Posts: 23
Try out this at the command prompt

set CLASSPATH=%CLASSPATH%;c:\program files\apache group\tomcat 4.1\common\lib\*.jar


And try to compile it
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
that is to set the classpath right.so now i have write those code at the command promp as below

c:\Documents and Settings>set CLASSPATH=%CLASSPATH%;c:\program files\apache group\tomcat 4.1\comman\lib\*.jar

after i enter i prompt back the

c:\Documents and Settings

after that i need to compile my .java file that i store in

c:\program files\apache group\tomcat 4.1\webapps\testing\classes\IntsServlet.java

from that c:\Documents and Settings i need to change the directory to and compile it like below:

c:\Documents and Settings cd c:\program files\apache group\tomcat 4.1\webapps\testing\classes>javac IntsServlet.java

is all the step correct?if i do exactly like the above, i get an error msg says that'javac' is not recognize as an internal or external command

i really...really confuse.
i'm new in servlet technology and all this error making me more confuse
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
ok...right now i have compile the file ang i got the .class file.i copy the file and put in the classes folder in the server.when i want to browse the html page from my machine, i got this error msg :

The requested resource (/speech/testing/WEB-INF/classes/IntsServlet.class) is not available

how to solve this problem?
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Did you map your servlet to the web.xml file of your application.

It is mandatory that you map the servlet class file with the particular name
and the server will read the web.xml file to get this mapping.

If we don't map our servlets to the web.xml file, the server can't recognize our servlet and it will not be called.

Try mapping the servlet to the web.xml...I hope this would solve the problem.

For your reference, a sample mapping is as follows :



Try this out.

Cheers,
Swamy
Bindesh Vij
Greenhorn

Joined: Oct 27, 2004
Posts: 23
I believe the call made to the servlet is incorrect

The requested resource (/speech/testing/WEB-INF/classes/IntsServlet.class) is not available


My suggestion is try to create a web.xml as Swamy has suggested and put it your "<web-root-folder>/WEB-INF/" folder.

Put this command in the browser,after running tomcat

http://localhost:<port>/<web-root>/<servlet-name>

here
<port> = specifiest the port at which tomcat is listening for http request.If you have not specified it then it will be 8080. To check just try
http://localhost:8080/
This should bring the Tomcat start page.

<web-root> =your web root folder as copied into the webapps folder( as is apparent in your case it seems like testing is your root folder,ensure that you copy it in your webapps folder in tomcat)

<servlet-name>= your servlet name in this case IntsServlet. Note you should not give ".class" extension while calling the servlet.

So iam putting an example of how it would seem



just try this
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Hi,

If you are using JSPs, Servlets and building your own Web Application, I think the points I used. Might be helpful to you. I am posting them here.



The things that we have to look into while creating our own web apps are

1. The directory structure is proper
say some c:\Tomcat\webapps\OwnApp

2. Then inside our application, we need to create a web-inf
say c:\Tomcat\webapps\OwnApp\WEB_INF

3. Then we can arrange our own things here in this space

a. Java Script Files
say c:\Tomcat\webapps\OwnApp\WEB_INF\script - say

b. CSS
say c:\Tomcat\webapps\OwnApp\WEB_INF\css - Say

c. Images
say c:\Tomcat\webapps\OwnApp\WEB_INF\Images - say

d. Of course our servlets will be in the classes folder

say c:\Tomcat\webapps\OwnApp\WEB_INF\classes.

e. And beans in a package
say c:\Tomcat\webapps\OwnApp\WEB_INF\classes\mypack\mybeans\com\SomeBeanClass

And don't forget to have your own web.xml configured for new servlets....


Hope you find it useful...

Cheers,
Swamy
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
i've follow the instruction about web.xml. locally when i test the page,it success. but after put it in the server and browse it from my machine it gives me error that says, even, the html page

the resource is not available....

what happen now....
Bindesh Vij
Greenhorn

Joined: Oct 27, 2004
Posts: 23
Just try to list the contexts in the web folder by typing this at the prompt

http://localhost:<port>/<web-root-folder-name>/


This will list the files deployed in the tomcat against the given webapplication. And then click on the page that you want to view..
Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
its still cannot work....plzz.whats the problem?
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
You talked about an html page. So I wonder ... if you say that the local test was OK, did you call the HTML page from within Tomcat (using a URL beginning with http://localhost:8080) ? Or did you just test it using IE or another browser.

Besides, if I'm not mistaken you cannot call an html page directly with Tomcat. Each html page should have a .jsp suffix so Tomcat will think it's a Java Server Page.

If your web application did work completely local and you could view every page on your standalone machine, and the web application does not work on your server, it could be that the server works with another kind of structure.

I had the same problem : locally I work with the folder /gco so I called the web app with the URL http://localhost:8080/gco/MOPO.

On the web server every servlet should be called with a /servlet prefix. So, there the URL to call my web app is http://www.gertcuppens.org/servlet/MOPO.

The solution ? 2 different web.xml files : one for the PC and one for the server.
Bindesh Vij
Greenhorn

Joined: Oct 27, 2004
Posts: 23
Do one thing, list step by step the heirarchy of the web directory as well as the way you are trying to deploy it..if u miss a single step ..then it will be really hard to find the bug
Charukeshi Pathak
Greenhorn

Joined: Apr 14, 2004
Posts: 3
Hi Suki,

Please state the step by step directory structure so that we can cross check whether you are missing a step.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compile?????