• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

problem with programming using MVC techniques

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming you're in the WEB-INF directory...
Try:

[ June 05, 2006: Message edited by: Ben Souther ]
 
rajsunder reddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
Assuming you're in the WEB-INF directory...
Try:



thanks for the info, got to try it once i reach home
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
can u please explain what this part does \:classes:src:.
thanks
vinay
[ June 05, 2006: Message edited by: vinay vinay ]
 
rajsunder reddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW i got some hint from one weblogic administrator who i know, he said that along with the path for the servlet-api.jar i need to pass the path for the directory classes where my class files are stored

C:\Tomcat\webapps\MVCProj>javac -classpath c:\tomcat\common\lib\servlet-api.jar;c:\tomcat\webapps\MVCProj\classes;. -d classes src\com\example\web\TableSelect.java

the path in the block letters is what i have to add.
will try it once i reach home
 
Vinay Thippeswamy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
typing that path servlet-api.jar i one headache. i have found some other way to do this. first you have to make this servlet-api.jar visible to the compiler. put these under your environment variables.

CLASSPATH:
C:\SW\JAVA\jre\lib\rt.jar;C:\SW\JAVA\TOM\common\lib\servlet-api.jar;C:\SW\JAVA\TOM\common\lib\jsp-api.jar;.;

CATALINA_HOME:
c:\sw\java\tom

JAVA_HOME:
C:\Sw\Java\jdk

path:
C:\Sw\Java\jdk\bin;C:\Sw\tom\bin;

additionaly i have also put

path=%path%;C:\SW\JAVA\jdk\bin;
CLASSPATH=;.;

in autoexec.bat in c:\


now change them to your respective directory.
install stuff in least path like c:\sw\java so that they are easy to type.

to compile i do the following.

javac -d ..\classes ..\src\Ch1servlet.java

the above line i execute from the classes directory. i do this because i got confused with that :classes:. parameter. if some one can please explain what that : and . does.
do yourself a favour put the following line in a file

javac -d ..\classes ..\src\Ch1servlet.java

and name that file as exe.bat and put that into you classes directory.
then type exe at the prompt i.e, in the classes directory. to change that command if you want to, just edit exe.bat in notepad and save it. now all u have to type is exe not that whole command once again.

by the way in your case you have to put the line as

javac -d ..\classes ..\src\com\example\model\TableExpert.java


regards
vinay.
[ June 05, 2006: Message edited by: Vinay Thippeswamy ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic