Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBean from a servlet - still not resolved

 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying JavaBean for the first time- should be simple but i am not getting it

My servlet and JavaBean are in the same directory (\MyProjects\Person)

servlet code:

public class PersonServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();
p.setName("Evan");
request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

Javabean:

public class Person{
private String name;

public void setName(String name){
this.name = name;
}

public String getName(){
return name;
}
}

I compiled Person.java first and class file exists in the same directory but when i try to compile PersonServlet.java, i get

PersonServlet.java:12: cannot resolve symbol
symbol : class Person
location: class PersonServlet
Person p = new Person();
^
PersonServlet.java:12: cannot resolve symbol
symbol : class Person
location: class PersonServlet
Person p = new Person();

Thanks

[ June 12, 2005: Message edited by: HS ]

[ June 12, 2005: Message edited by: HS ]
[ June 14, 2005: Message edited by: HS ]
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to define package name at top of both classe using

package name;
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already tried that, same results.....
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it

set classpath till calsses dierctory

means

on command line say

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\testJSP\WEB-INF\classes;

it will definately work
bye
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I specified the classpath, as you have suggested but still it does not work...

Thanks
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI HS

Can you please post your exact code with the imports as well as the exact directory structure otherwise it is difficult for us to help
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Shiva:

Code is under : C:\Javacode\MyProjects\Persons

Person.java :-

package Persons;

public class Person{
private String name;

public void setName(String name){
this.name = name;
}

public String getName(){
return name;
}
}

PersonServlet.java :-


package Persons;

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

public class PersonServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();
p.setName("Evan");
request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}

result.jsp :-

<html><body>
Person is: <%= request.getAttribute("person") %>
</body></html>

Set classpath to C:\Javacode\MyProjects\Persons

Compiled Person.java but get following when compiling PersonServlet.java:

PersonServlet.java:12: cannot resolve symbol
symbol : class Person
location: class PersonServlet
Person p = new Person();

Thanks a lot
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi HS ,
just tried your code . you dont need to set your classpath to classes

Make sure you set the servlet jar in classpath
then run the follwoing commands

javac -d . Persons/Person.java
javac -d . Persons/PersonServlet.java

Make sure you issue this command from C:\Javacode\MyProjects

I have tried this and it compiles properly

Please tell me once it works

Thanks
Shiva
 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Shiva:

It worked ..thanks a lot
[ June 14, 2005: Message edited by: HS ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic