• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptless JSP

 
Steve Jerome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doPost(HttpServletRequest req,HttpServletResponse res)throws

IOException,ServletException
{
Person p=new Person();
p.setName("Jerome");
req.setAttribute("per",p);
//PrintWriter pw=res.getWriter();
//Person p1=(Person)req.getAttribute("per");
//pw.println(p1.getName());
RequestDispatcher view=req.getRequestDispatcher("result.jsp");
view.forward(req,res);
}
An error occurred at line: 3 in the jsp file: /result.jsp
Person cannot be resolved to a type
1: <html>
2: <body>
3: Person's name is<%Person p=(Person)request.getAttribute("per"); %>
4: <%=p.getName()%>
5: </body></html>


It's a program in page 345.when I run the servlet program alone it displays the name correctly.but if I pass the iformation to jsp file it's displaying the above server error.Person is a simple java class with getName(),setName() methods.can anyone help me out in this.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Person is in a package isn't it ? So you have to import the package, using the "import" attribute of the "page" directive. Or explicitly naming the package.
For example, if Person is in the "beans" package :



If Person is not in a package, put it in one ! Putting classes in the default package may give unpredictable results.
 
Steve Jerome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris after putting my classes in package the code runs fine now.
[ July 14, 2007: Message edited by: Steve Jerome ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic