• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to compile servlets

 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in order to run servlets we must place complied *.class files in web-inf->classes directory..
but how to compile them

they are not getting compling just by javac filename.java
?

i know its silly but still tell me
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are not getting compling just by javac filename.java


That is the way to compile Java classes; servlets do not differ in that regard from other Java classes. What happens if you do it that way? (You will of course need to have the Servlet API jar file in your classpath.)
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx...got compiled ...thats the classpath i m missing..

thanx again..

now this problem is comming..


Status report
message /jsp_prac/index.html
description The requested resource (/jsp_prac/index.html) is not available.

i have put jsp_prac in webapps and under that there is file index.html...

i don't know why its showing like this
[ July 22, 2005: Message edited by: amit taneja ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your jsp_prac directory contain a WEB-INF subdirectory? Tomcat needs that to recognize a directory as a web application.
 
R K Parulekar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit
Your application jsp_prac should be under webapps.
1 Create folder named jsp_prac under webapps
2 Create folder WEB-INF under jsp_prac
3 Create folder classes under WEB-INF.
4 Put all your *.class files under classes (With proper package structure)
5. Copy your index.html in jsp_prac
6 Create web.xml file under WEB-INF to desctibe your servlet
7.Restart your application.

Now it should work !

Cheers !
Ravi
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx guys..


it runs
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in order to run servlets we must place complied *.class files in web-inf->classes directory


I am not sure for the above statement? If anybody provide me any link which talks about the servlet deployment in couple of APP servers.
 
amit taneja
Ranch Hand
Posts: 813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now other error is comming...

i am making mvc model

and for model i have code like

package com;
import java.util.*;

public class phoneDir
{

public List getPhone(String name)
{
List phone=new ArrayList();

if (name.equals("amit"))
{
phone.add("9873085014");
phone.add("01122721799");

}
else
{
phone.add("unknown");
phone.add("unknown");
}
return phone;
}

}



and for controller i have code like

package com;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import phoneDir;

public class testing extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException
{
res.setContentType("text/html");

PrintWriter out =res.getWriter();
out.println("<html> Hack the matrix </html>");
out.println(req.getParameter("name"));
out.println(req.getParameter("empid"));

phoneDir ph= new phoneDir();
List phone_no =ph.getPhone(req.getParameter("name"));

Iterator it= phone_no.Iterator();
while(it.hasNext())
{
out.println("<br> "+ it.next());
}
}
}


...and model got compile but ...controller is not getting compiled and following errro si comming..



C:\Tomcat5014\webapps\jsp_prac\WEB-INF\classes\com>javac testing.java
testing.java:6: '.' expected
import phoneDir;
^
1 error


can anybody tell me why ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure for the above statement? If anybody provide me any link which talks about the servlet deployment in couple of APP servers.

The location of compiled class files and library jar files is defined in the servlet API - it is NOT a vendor option and has not been for years.
Why not download the servlet API and keep it handy.
This standardization is intended to make Java web applications portable.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!