Hi guys/gals,
my name is raj, i am new to this place. btw i am preparing for the webcomponent exam. I was practicing the examples in the book head first
servlets and
jsp.
the example is from chapter 3, hands on MVC. i just changed the example from a beer advice, to a application that gives multiplication tables as output given the firstnumber(say x) and secondnumber(say y), which are fed through a form to the application and the output is some thing like
X x 1 = X
.
.
.
.
.
X x Y = XY
in a table as a output, the code for the model is
*********************************************************************
package com.example.model;
import java.util.*;
import java.lang.Integer.*;
public class TableExpert
{
public List getTable(int firstNumber,int secondNumber)
{
List<
String> table=new ArrayList<String>();
for(int i=1;i<=secondNumber;i++)
table.add(firstNumber*i+"");
return(table);
}
}
*********************************************************************
which i placed in proper diirectory structure as said in the book(c:\tomcat\webapps\MVCProj\src\com\example\model\TableExpert.java)
there was no problem with compiling this program which i did using
C:\Tomcat\webapps\MVCProj>javac -classpath c:\tomcat\common\lib
\servlet-api.jar:classes:. -d classes src/com/example/model/TableExpert.java
, and the class file was created in the path c:\tomcat\webapps\MVCProj\classes\com\example\model\TableExpert.class
the code for the servlet is
**********************************************************************
package com.example.web;
import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TableSelect extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
String a1 = request.getParamater("firstnumber");
String a2 = request.getParameter("lastnumber");
try
{
int firstNumber = Integer.parseInt(a1);
int secondNumber = Integer.parseInt(a2);
TableExpert te= new TableExpert();
List result = te.getTable(firstNumber,secondNumber);
request.setAttribute("table",result);
request.setAttribute("firstNumber",firstNumber);
request.setAttribute("secondNumber",secondNumber);
RequestDispatcher view =
request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
catch(Exception e)
{}
}
}
*************************************************************************
which i tried to compile with the command
C:\Tomcat\webapps\MVCProj>javac -classpath c:\tomcat\common\lib\servlet-api.jar
:classes:. -d classes src\com\example\web\TableSelect.java
BTW the path for the
java file is
c:\tomcat\webapps\MVCProj\src\com\example\web\TableSelect.java
this is what i got after doing this
*************************************************************************
src\com\example\web\TableSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\TableSelect.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
src\com\example\web\TableSelect.java:5: package javax.servlet.http does not exis
t
import javax.servlet.http.*;
^
src\com\example\web\TableSelect.java:9: cannot find symbol
symbol: class HttpServlet
public class TableSelect extends HttpServlet
^
src\com\example\web\TableSelect.java:11: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.TableSelect
public void doPost(HttpServletRequest request,
^
src\com\example\web\TableSelect.java:12: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.TableSelect
HttpServletResponse response)
^
src\com\example\web\TableSelect.java:13: cannot find symbol
symbol : class ServletException
location: class com.example.web.TableSelect
throws IOException,ServletException
^
src\com\example\web\TableSelect.java:23: cannot find symbol
symbol : class TableExpert
location: class com.example.web.TableSelect
TableExpert te= new TableExpert();
^
src\com\example\web\TableSelect.java:23: cannot find symbol
symbol : class TableExpert
location: class com.example.web.TableSelect
TableExpert te= new TableExpert();
^
src\com\example\web\TableSelect.java:29: cannot find symbol
symbol : class RequestDispatcher
location: class com.example.web.TableSelect
RequestDispatcher view = request.getRequestDispatcher("r
esult.jsp");
^
10 errors
****************************************************************************
Can some one help me pls
[ June 04, 2006: Message edited by: rajsunder reddy ]