dcsimg
Struts Error:"org.apache.jasper.JasperException: Cannot find bean SearchResults in scope request"
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Madhuri_Cherukuri
Posted On:   Wednesday, July 16, 2003 02:12 PM

I am getting the following error when I try to iterate through my VO in my .jsp file. "org.apache.jasper.JasperException: Cannot find bean SearchResults in scope request" where "SearchResults" is the attribute which i set for my VO. ok, here is what I am doing. can u please correct me where I am going wring. I am doing search page and I created a collection for the search results. I want to display those results in the SearchResults.jsp I am attaching my code. This is my logic 1.Blog.java - A bean class for my blog attributes 2.TempBlogArray - A collection of blogs 3.SearchAction.execute - I created a list to store the TempBlogArray, and I am using    More>>

I am getting the following error when I try to iterate through my VO in my .jsp file.



"org.apache.jasper.JasperException: Cannot find bean SearchResults in scope request" where "SearchResults" is the attribute which i set for my VO.



ok, here is what I am doing. can u please correct me where I am going wring. I am doing search page and I created a collection for the search results. I want
to display those results in the SearchResults.jsp



I am attaching my code. This is my logic



1.Blog.java - A bean class for my blog attributes

2.TempBlogArray - A collection of blogs

3.SearchAction.execute - I created a list to store
the TempBlogArray, and I am using
request.setAttribute("SearchResults", List);

4. In my SearchResults.jsp ( I am importing "Blog" ,
then in line 218 i have the logic:iterate code.
where in I am using these lines




scope="request" collection="SearchResults"


property="title"/>




5. In place if collection I tried using
type="aBlog", but it is assigning a null value to
the aBlog here and i am getting different errors
here.



6. I also added the scope in my struts-config.xml as





type="SearchResultsAction" name="searchResultsForm"
scope="request" input="/SearchResults.jsp"



Any help regarding this error would be gratly
appreciated.



Thanks,
Madhuri.



Souce Code -
-------------------------------------------------
Blog.java


/**
* Created by IntelliJ IDEA.
* User: Madhuri
* Date: Jul 14, 2003
* Time: 11:11:20 PM
* To change this template use Options | File Templates.
*/
package core;
public class Blog {

long blog_id;
String title;
String description;
String location;
String category;
int rank;
int parent_blog_id;
String message;
String owner;
String create_date;
String update_date;
String blog_type;
int publish_flag;
String publish_date;
int is_atchmt_present;
int Num_of_Threads;

public long getBlog_id() {
return blog_id;
}

public void setBlog_id(long blog_id) {
this.blog_id = blog_id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public int getRank() {
return rank;
}

public void setRank(int rank) {
this.rank = rank;
}

public int getParent_blog_id() {
return parent_blog_id;
}

public void setParent_blog_id(int parent_blog_id) {
this.parent_blog_id = parent_blog_id;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getOwner() {
return owner;
}

public void setOwner(String owner) {
this.owner = owner;
}

public String getCreate_date() {
return create_date;
}

public void setCreate_date(String create_date) {
this.create_date = create_date;
}

public String getUpdate_date() {
return update_date;
}

public void setUpdate_date(String update_date) {
this.update_date = update_date;
}

public String getBlog_type() {
return blog_type;
}

public void setBlog_type(String blog_type) {
this.blog_type = blog_type;
}

public int getPublish_flag() {
return publish_flag;
}

public void setPublish_flag(int publish_flag) {
this.publish_flag = publish_flag;
}

public String getPublish_date() {
return publish_date;
}

public void setPublish_date(String publish_date) {
this.publish_date = publish_date;
}

public int getIs_atchmt_present() {
return is_atchmt_present;
}

public void setIs_atchmt_present(int is_atchmt_present) {
this.is_atchmt_present = is_atchmt_present;
}
public int getNum_of_Threads() {
return Num_of_Threads;
}

public void setNum_of_Threads(int num_of_Threads) {
Num_of_Threads = num_of_Threads;
}
}


-------------------------------------------------

TempBlogArray.java

/**
* Created by IntelliJ IDEA.
* User: Madhuri
* Date: Jul 14, 2003
* Time: 11:30:06 PM
* To change this template use Options | File Templates.
*/
package core;

import java.util.ArrayList;

public class TempBlogArray {

public ArrayList getBlogList()
{
ArrayList blogList;
blogList = new ArrayList();

Blog aBlog = new Blog();

aBlog.setBlog_id(1);
aBlog.setBlog_type("C");
aBlog.setCategory("Food");
aBlog.setPublish_flag(0);
aBlog.setRank(5);
aBlog.setTitle("Restaurants in San Jose");

blogList.add(0, aBlog);

aBlog.setBlog_id(2);
aBlog.setBlog_type("C");
aBlog.setCategory("Food");
aBlog.setPublish_flag(1);
aBlog.setRank(4);
aBlog.setTitle("Mexican & Japanese Restaurants in San Jose");

blogList.add(1, aBlog);

aBlog.setBlog_id(3);
aBlog.setBlog_type("C");
aBlog.setCategory("Music");
aBlog.setPublish_flag(1);
aBlog.setRank(4);
aBlog.setTitle("classical guitar,San Jose");

blogList.add(2, aBlog);

aBlog.setBlog_id(4);
aBlog.setBlog_type("C");
aBlog.setCategory("Music");
aBlog.setPublish_flag(1);
aBlog.setRank(4);
aBlog.setTitle("Guitar Shows Dying ?");

blogList.add(3, aBlog);

return blogList;
}
}


----------------------------------------------------------------

SearchAction.java


/**
* Created by IntelliJ IDEA.
* User: Madhuri
* Date: Jul 15, 2003
* Time: 12:09:54 AM
* To change this template use Options | File Templates.
*/
import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import core.*;

public class SearchAction extends Action
{
protected List getSearchResults(String keyword)
{
TempBlogArray blogArray = new TempBlogArray();
List resultBlogList = new ArrayList();
Blog aBlog;

if ( keyword.equalsIgnoreCase("FOOD") )
{
aBlog = (Blog)(blogArray.getBlogList().get(1));
resultBlogList.add(aBlog);
return resultBlogList;
}
return resultBlogList;
}

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,
HttpServletResponse response)throws IOException, ServletException
{
List resultList = null;

// Default target to success
String target = new String("success");

if ( form != null )
{
// Use the SearchForm to get the search keyword
SearchForm searchForm = (SearchForm)form;
String keyword = searchForm.getKeyword();
resultList = getSearchResults(keyword);
}

// Set the target to failure
if ( resultList == null )
{
target = new String("failure");
}
else
{
System.out.println("SearchAction: result = " + resultList);
request.setAttribute("SearchResult", resultList);
}

// Forward to the appropriate View
return (mapping.findForward(target));

} // end of execute
}


------------------------------------------------------------

SearchForm.java


/**
* Created by IntelliJ IDEA.
* User: Madhuri
* Date: Jul 15, 2003
* Time: 11:25:52 AM
* To change this template use Options | File Templates.
*/

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class SearchForm extends ActionForm
{
private String keyword = null;

public String getKeyword()
{
return (keyword);
}

public void setKeyword(String keyword)
{
this.keyword = keyword;
}

public void reset(ActionMapping mapping,HttpServletRequest request)
{
this.keyword = null;
}
}


-----------------------------------------------

SearchResults.jsp ( i am giving only the relevant code here)

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ page import ="java.util.*" %>
<%@ page import ="core.Blog" %>



<%String myKeyword = (String)request.getAttribute("SearchResults");%>

<%=request.getAttribute(myKeyword)%>" >
















------------------------------------------------------------

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

"C:jakarta-struts-1.1-b3webappsstruts-documentationdtdsstruts-config_1_1.dtd">





















   <<Less
About | Sitemap | Contact