• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaBean from a servlet - still not resolved

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already tried that, same results.....
 
Sanjay pts
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I specified the classpath, as you have suggested but still it does not work...

Thanks
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Shiva:

It worked ..thanks a lot
[ June 14, 2005: Message edited by: HS ]
 
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic