Magazine
 
Integrating Struts and Hibernate
 

</table>
</html:form>
</body>
</html:html>

Save SearchTutorial.jsp in to “C:\Struts-
Hibernate-Integration\code\pages”
directory.
2. Search Result Page (SearchResultPage.jsp) This page is used to display the search result. Here is the code of search result page:

<%@page language=”java”
import=”java.util.*”%>
<%@ taglib uri=”/tags/struts-bean”
prefix=”bean” %>
<%@ taglib uri=”/tags/struts-html”
prefix=”html” %>
<p><font size=”4" color=”#800000"
face=”Arial”>Search Results</font></p>
<%
List searchresult = (List)
request.getAttribute(“searchresult”);
%>
<%
for (Iterator itr=searchresult.iterator();
itr.hasNext(); )
{
roseindia.net.dao.hibernate.Tutorial tutorial
=
(roseindia.net.dao.hibernate.Tutorial)itr.next();
%>
<p>
<a href=”<%=tutorial.getPageurl()%>”>
<font face=”Arial” size=”3">
<%=tutorial.getShortdesc()%></font>
</a><br>
<font face=”Arial” size=”2">
<%=tutorial.getLongdesc()%></font></p>
<%
}
%>
<html:link page=”/pages/SearchTutorial.jsp”>
Back to Search Page</html:link>

Save SearchResultPage.jsp in to “C:\Struts-Hibernate- Integration\code\pages” directory.

 

3. Search Java Form
(SearchTutorialActionForm.java)
This is the Struts action form class. Here is
the code of the Action Form:

package roseindia.web;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class SearchTutorialActionForm
extends ActionForm
{
private String keyword=null;
public void setKeyword(String keyword){
this.keyword=keyword;
}
public String getKeyword(){
return this.keyword;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.keyword=null;
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request ) {
ActionErrors errors = new ActionErrors();
if( getKeyword() == null ||
getKeyword().length() < 1 ) {
errors.add(“keyword”,new
ActionMessage(“error.keyword.required”));
}
return errors;
}
}

4. Search Action Class
(SearchTutorialAction.java)
This is Struts Action Class of our application. Here is the code of the Action Class: package roseindia.web;
import javax.servlet.http.HttpServletRequest;

Dec 2007 | Java Jazz Up | 59
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF