| View previous topic :: View next topic |
| Author |
Message |
Datta Guest
|
Posted: Tue Sep 12, 2006 2:42 pm Post subject: How to populate Jsp page from ActionServlet |
|
|
Hi all,
In my application, input.jsp page takes a keyword based on that it has to search D:\somedir, when the pattern matches it lists some files like if i give abc as keyword, it lists all files that contains "abc" in its filename all such files are retrieved. And i want to display the files names in another Jsp page. My input.jsp page is:
<body>
<html:form action="/searchPattern">
<TABLE border="0">
<TBODY>
<TR>
<TH>File Pattern</TH>
<TD><html:text property="pattern" /></TD>
</TR>
<TR>
<TD><html:submit property="submit" value="Submit" /></TD>
</TR>
</TBODY>
</TABLE>
</html:form>
</body>
and results.jsp is:
<body>
<jsp:useBean class="com.mot.struts.form.SearchForm" id="fileDetail" scope="session"/>
<table>
<tr>
<td>File Names</td>
<td><jsp:getProperty name="fileDetail" property="pattern"/></td>
<td><ul>
<logic:iterate name="fileDetail" property="listFiles"
id="fileDetails" scope="session">
<li>
<bean:write name="fileDetails" property="listFiles" />
</li>
</logic:iterate>
</ul></td>
</tr>
</table>
</body>
and ActionServlet is:
SearchForm searchForm = (SearchForm) form;
String pattern=request.getParameter("pattern");
File dir = new File("D:\\satish\\archive");
System.out.println("Searching....");
File[] children=dir.listFiles();
for (int i=0; i<children.length; i++) {
String fileMatch=children[i].getAbsoluteFile().getName(); if(fileMatch.contains(pattern)==true){
System.out.println("File pattern with .log found, File Name "+ fileMatch); request.setAttribute("fileDetail", searchForm);
return mapping.findForward("success");
}
else{
System.out.println("File pattern does not found");
}
}
return mapping.findForward("failure");
}
}
and the FormBean class is:
private String pattern;
private List listFiles;
public SearchForm(){
}
public SearchForm(String pattern){
this.pattern=pattern;
}
public String getPattern() {
return pattern;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
public List getListFiles() {
return listFiles;
} //What code shud i write here
public void setListFiles(List listFiles) {
this.listFiles = listFiles;
Plz help me. Thanks a lot
} |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|