aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Scriptless JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Scriptless JSP" Watch "Scriptless JSP" New topic
Author

Scriptless JSP

Steve Jerome
Greenhorn

Joined: Mar 03, 2007
Posts: 22
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Steve Jerome
Greenhorn

Joined: Mar 03, 2007
Posts: 22
Thanks Chris after putting my classes in package the code runs fine now.
[ July 14, 2007: Message edited by: Steve Jerome ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scriptless JSP