How to use struts
hi, i m newbie..
how can i use struts in my jsp page.
i have Jakarta Tomcat4.1.24 ,
i configured the struts in following way
Tomcat_home/webapps/root/Registeruser
in ---registeruser
---web-inf
----classes
----lib
strut.jar and servlet.jar
-----src
-----index.jsp
and in web-inf i put some of the tld files
i m getting this error
org.apache.jasper.JasperException: File "/WEB-INF/struts-bean.tld" not found
so what is the suggestion
?
Similar Messages
-
How to use struts 1.3.5 with WebSphere (WSAD) 5.1.2
Hi I want to work in WSAD 5.1.2 using struts, Will anyone please let me know how to configure this.
Thanks.Hi I want to work in WSAD 5.1.2 using struts, Will anyone please let me know how to configure this.
Thanks. -
How to use struts Logic tags in weblogic8.1
hi
i have used jakarta struts in JDeveloper there i used logic tags
but the same i have to use in weblogic8.1 ,how should i use it
i am new to weblogic platform
it is very urgent
pleaseHi harish,
Procedure for using a Struts Tag Libraries in weblogic 8.1 :
•Copy the tag lib jar files under WEB-INF/lib ( if tag handler supplied as
classes without package a jar file then we need to copy the classes
under WEB_INF/classes.
• Copy the tld files files under WEB-INF or create a directory under
WEB-INF and copy tld files under this directory.
• We need to give the information about the tag libraries in web.xml by
adding the following lines to it as,
<taglib>
<taglib-uri>bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
To use tags in jsp file we need to add taglib directive as ,
<%@ taglib uri="logic" prefix=“logic"%>
<%@ taglib uri="html" prefix=“html"%>
<%@ taglib uri="bean" prefix=“bean"%>
Every tag can support zero or more number of attributes and a tag may or
may not support body content
Every Tag Library Uniquely identified by uri defined in web.xml.
we can use the tags in jsp according to the tags and attributes which are defined in *.tld files.
if we look at .tld files we can find several tags and its attributes.
note :any jar files that are related to struts framework ,place under the lib directory of the webapplication.
----- Anilkumar kari -
How to use struts in a jsp where controls are dynamically decided
Hi,
In My JSP...
I don't know how many text field,listbox,radio button i need to display...
Depending on the user naviagation it is dynamically decided ... how many all the above mentioned control (text field,listbox,radio ) need to display.
Here the problem is all the name of the control (text field,listbox,radio ) are dymaically decided..so in this case how do i wirte setter and getter in the Action Form.
Thanks
balajiindexed or mapped fields... For example, in the form, you have this:
private HashMap map = new HashMap();
public Object getField(String key) {
return (map.get(key));
public void setField(String key, Object value) {
map.put(key, value);
}Then in the JSP:
<html:text property="field(fieldName)" /> Where the "field(.." part is the property name (get/setField) and the "..(fieldName)" part is a unique key for the map. This can be simply done as field(text1), field(text2), etc.
There are also index fields, where you use an Object array (I think) and field[index] as the name (field[0], field[1], etc.). You can use <%= %> scriptlets to write the property value for the tag, of course. -
Anyone here knows how to use struts??Please show me some examples
As above..
Download Struts and install it in the downloaded binary there are lot of examples provided by the Struts team.
-
How to use the validation.xml in struts validation?
Can any one please help me, how to use the validation.xml in struts validation? possible please give me simple example.
Edited by: SathishkumarAyyavoo on Jan 31, 2009 12:03 PMThese 2 are the good articles for the beginners to do validation things in Struts. you can follow any one of them.
1. [http://viralpatel.net/blogs/2009/01/struts-validation-framework-tutorial-example-validator-struts-validation-form-validation.html]
2. [http://www.vaannila.com/struts/struts-example/struts-custom-validation-example-1.html]
All the best. -
How to assign bean value to a local variable in JSP using struts.
Hi everybody!
I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
we can have someting like this to display the value
<bean:write name="detailService" property="status" />or
<bean:define id="theStatus" name="detailService" property="status"/>
This is country: <%=theStatus%>but an error occured when I tried like this:
String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
or
String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
Any help pretty much appreciatedJava != JSP.
The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
The <bean:write> tag naturally just writes out what you tell it to.
The <bean:define> tag defines a local variable, and gives it a value.
this should do it.
<bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
<%
String currentStatus = theStatus;
%>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write. -
How to use logic:present tag in struts el tag
Hi
I am trying to use struts el tags in the jsp page.I am struggling with the following exception: Cannot find bean: "result" in any scope.I couldn't understand why this error is coming even i had the property "result" in my ActionForm.
ActionForm:
package com.finocus.cam.struts.bean;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import com.finocus.cam.common.ValidateFormat;
public class DetailsForm extends org.apache.struts.action.ActionForm {
private final static String LOG_TAG = DetailsForm.class.getName() + ".";
private static final long serialVersionUID = 1L;
// VARIABLES DECLARATION
private String name = null;
private String searchField = null;
private String searchCriteria = null;
private String phonenumber = "";
private String email = "";
private List results = null;
private String adminUserName = "";
private String adminUserEmail = "";
public DetailsForm() {
// GETTER AND SETTER METHODS
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public String getSearchCriteria() {
return searchCriteria;
public void setSearchCriteria(String searchCriteria) {
this.searchCriteria = searchCriteria;
public String getSearchField() {
return searchField;
public void setSearchField(String searchField) {
this.searchField = searchField;
public String getEmail() {
return email;
public void setEmail(String email) {
this.email = email;
public List getResults() {
return results;
public void setResults(List results) {
this.results = results;
public String getPhonenumber() {
return phonenumber;
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
public String getAdminUserEmail() {
return adminUserEmail;
public void setAdminUserEmail(String adminUserEmail) {
this.adminUserEmail = adminUserEmail;
public String getAdminUserName() {
return adminUserName;
public void setAdminUserName(String adminUserName) {
this.adminUserName = adminUserName;
// DUMPING THE VALUES IN THE CONSOLE
public void dumpValues() {
StringBuffer sb = new StringBuffer();
sb.append("Name'");
sb.append(name);
sb.append("SearchField");
sb.append(searchField);
sb.append("searchCriteria");
sb.append(searchCriteria);
sb.append("'");
sb.append(" ");
System.out.println(sb.toString());
// RESET() METHOD IS USED FOR STORE FORM'S CURRENT VARIABLES DECLARATION
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
System.out.println("reset() method is called");
this.email = null;
this.searchCriteria = null;
this.searchField = null;
this.results = null;
// VALIDATE() METHOD IS USED TO VALIDATE THE FORM DATA
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
System.out.println("Validate()is called");
// Determine if name has been entered.
if (getName() == null || getName().length() == 0
|| getName().equals(" ")) {
errors.add("accountText", new ActionError("searchText.error"));
} else if ((getSearchField().equals("name") == true)
&& (ValidateFormat.isValidText(getName()) == false)) {
errors.add("validAccountName", new ActionError("validName.error"));
if (getSearchField() == null || getSearchField().length() == 0) {
errors.add("accountSearchField", new ActionError(
"searchField.error"));
} else if ((getSearchField().equals("email") == true)
&& (ValidateFormat.isValidEmail(getName()) == false)) {
errors
.add("validAccountEmail", new ActionError(
"validEmail.error"));
} else if ((getSearchField().equals("phonenumber") == true)
&& (ValidateFormat.isValidPhoneNoFormat(getName()) == false)) {
errors.add("validPhoneFormat", new ActionError(
"validPhoneFormat.error"));
if ((getSearchField().equals("searchallfields"))
&& ((ValidateFormat.isValidText(getName()) == false)
&& (ValidateFormat.isValidEmail(getName()) == false) && (ValidateFormat
.isValidPhoneNoFormat(getName()) == false))) {
errors.add("validNameEmail",
new ActionError("validNameEmail.error"));
return errors;
Action class:
package com.finocus.cam.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.finocus.cam.db.CAMDbAccess;
import com.finocus.cam.struts.bean.DetailsForm;
public class DetailsAction extends org.apache.struts.action.Action implements
com.finocus.cam.common.CAMConstants {
private final static String LOG_TAG = DetailsAction.class.getName() + ".";
// Global Forwards
public static final String GLOBAL_FORWARD_search = "login";
// Local Forwards
public static final String SUCCESS_search = "success";
private boolean dumpRequestParams = true;
public DetailsAction() {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("SearchAccount execute() is called");
HttpSession session = request.getSession(true);
ArrayList results = null;
DetailsForm search = (DetailsForm) form;
String name = search.getName();
String searchField = search.getSearchField();
String searchCriteria = search.getSearchCriteria();
// Dumping the values of input patameters
if (dumpRequestParams == true) {
request.setAttribute("SearchCriteria", searchCriteria);
request.setAttribute("SearchField", searchField);
request.setAttribute("Text", name);
search.dumpValues();
// Perform search based on what criteria and search Field was entered.
CAMDbAccess dbAccess = CAMDbAccess.getInstance();
if (null != searchCriteria && searchField != null) {
System.out.println("Search Criteria =" + searchCriteria
+ "Selected Option =" + searchField);
if (searchCriteria.equals(Search_Account) && searchField != null) {
results = dbAccess.searchByAccountInfo(name, searchCriteria,
searchField);
System.out.println(" Search criteria :Exact Match was selected.<BR>");
// Place search results in SearchForm for access by JSP.
search.setResults(results);
// Forward control to this Action's input page.
return mapping.findForward(SUCCESS_search);
My jsp page:
<%@ taglib uri="/WEB-INF/tld/struts-bean" prefix="bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic-el" %>
<%@ taglib uri="/WEB-INF/tld/struts-html" prefix="html" %>
<html:html>
<head>
<title>Search Page</title>
</head>
<body colorants="LightGreen">
<table width="100%" bgcolor="LightGreen">
<tr>
<td align="left"><font color="brown"><h3><b>Search Info</b></h3></font><hr></td>
</tr>
<tr>
<td align="left"><h4><font color="brown"><b>Search Text:</b></font><%=request.getAttribute("Text")%></h4></td>
</tr><tr>
<td align="left"><h4><font color="brown"><b>Search Field:</b></font><%=request.getAttribute("SearchField")%></h4></td>
</tr><tr>
<td align="left"><h4><font color="brown"><b>Search Criteria:</b></font><%=request.getAttribute("SearchCriteria")%></h4></td>
</tr><tr>
<html:form action="/results.do">
<td><center><html:submit value="AllSearchOptions " /></center></td>
</html:form>
</tr>
<tr>
<td align="left"><font color="brown"><hr><h2><b>Search Results</b></h2></font></td>
</tr>
<tr>
<td>
<table border="1" cellspacing="1" cellpadding="3" width="70%"
bgcolor="white">
<logic:present name="searchbyaccount" property="results">
Results exists
<c:if test="${size==0 }">
<center><font color="red"><b>No Results Found</b></font></center>
</c:if>
<br>
<c:if test="${size>0}">
Size is greater than ZERO
<table border="1" cellspacing="1" cellpadding="3" width="70%"
bgcolor="white">
<tr>
<th>Customerid</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>phone Number</th>
<th>Details</th>
</tr>
<c:forEach var="result" items="${results}">
<c:out value="${result}"/>
<tr>
<td><bean:write name="result" property="customerid"></bean:write></td>
<td><bean:write name="result"
property="accountAdminFirstName"></bean:write></td>
<td><bean:write name="result"
property="accountAdminLastName" /></td>
<td><bean:write name="result" property="accountability" /></td>
<td><bean:write name="result" property="accountAdminPhone" /></td>
<td><html:form action="/accountDetails.do">
<html:submit value="Details" />
</html:form></td>
</tr>
</c:forEach>
</table>
</c:if>
</logic:present>
</table>
</td>
</tr>
</table>
</body>
</html:html> Please refer me where i done a mistake.Thanks in Advancehi all,
I am doing programs in sturts. My program
My program purpose is to retrieve data from the
database.My database is MySql. I know that we can
write connection code in Action Class, it is ok for
some less prog's if i want to use the sane connection
code in more Action Classes it is vasting time and
so.I don't think it's a good idea to put database code in Action classes. (That's one of the biggest drawbacks of Struts - it's completely tied to Actions, HTTP, and the Web.) Better to move that code into plain old Java objects and let the Actions call them.
You'll be able to test them without the container or Struts, and you'll be able to reuse those objects in other, non-Web contexts.
So i want to use <data-sources> tag that is available
in struts-config.xml. I know that thre is tag withThis is the wrong place to configure a connection pool, too. Struts should have nothing to do with it. What if you change Web frameworks to WebWork or Spring? The connection pool should be configured in the container that hosts your app, not Struts.
this name, but the problem is i don't know how to use
this tag. If any budy know how to use this please
tell me the syntax or any example.
plese... reply soon..Don't do it. Think about doing it in your container, not Struts.
% -
How to get parameter and add it to hyperlink using struts tag?
Hi everyone:
There is a.jsp pass a parameter to b.jsp.How to get the parameter in b.jsp using struts Tag?I also want to add the parameter to a hyperlink in b.jsp.For example in b.jsp <html:link forward=.....>cxxxx</html:link>.How to add the parameter(get from a.jsp) to cXXXX in b.jsp?Try this:
Copy A Request Parameter - You can create a new bean containing the value of a parameter included in this request. If no parameter of the specified name was included, a request time exception will be thrown - therefore, it is common to nest the use of this tag inside a <logic:present parameter="xxx"> tag to ensure that the parameter was really included. If there is the possibility that more than one parameter of the same name was included, specify the "multiple" attribute (and the resulting value bean will be an array of String values, instead of a single String).
<bean:parameter id="name" name="name"/>
And then just use <html:link> with paramId. No java code at all. -
How to overwrite the value of a struts variable value using struts only
Say i define a variable using struts in my jsp
<bean:define id="aVar" value="abc" />
Now the variable has a value of abc , how can i overwrite it again to have another value --say "123"..
I need to change its value using struts only and not scriplet.
Kindly help ....This page may be helpful:
http://www.exampledepot.com/egs/javax.servlet.jsp/usebean.jsp.html -
How to use displaytags with struts
How to use display tags with struts to generate report from database
I think it would only consist in including the tag library of displaytags in the header and use the prefix of desplay tags.
Exporting the report from a database would only need to retrieve this information from the database as a List, Map or Collection of objects (beans) and display tem with the corresponding tag (table)
You have some more information here:
http://displaytag.sourceforge.net/11/tut_basic.html
Regards and good luck,
Fran Serrano. -
How to create web site using STRUTS frame work
Hi,
I know how to create web pages using JSP & Servlets.But now i have to create Matrimonial web site using STRUTS frame work.Plz any one guide for me...
Thank U....Struts is not to be confused with JSF.
Start at their own homepage over there at apache.org.
Good luck. -
How to use data-sources tag in struts-config.xml
hi all,
I am doing programs in sturts. My program purpose is to retrieve data from the database.My database is MySql. I know that we can write connection code in Action Class, it is ok for some less prog's if i want to use the sane connection code in more Action Classes it is vasting time and so.
So i want to use <data-sources> tag that is available in struts-config.xml. I know that thre is tag with this name, but the problem is i don't know how to use this tag. If any budy know how to use this please tell me the syntax or any example.
plese... reply soon..hi all,
I am doing programs in sturts. My program
My program purpose is to retrieve data from the
database.My database is MySql. I know that we can
write connection code in Action Class, it is ok for
some less prog's if i want to use the sane connection
code in more Action Classes it is vasting time and
so.I don't think it's a good idea to put database code in Action classes. (That's one of the biggest drawbacks of Struts - it's completely tied to Actions, HTTP, and the Web.) Better to move that code into plain old Java objects and let the Actions call them.
You'll be able to test them without the container or Struts, and you'll be able to reuse those objects in other, non-Web contexts.
So i want to use <data-sources> tag that is available
in struts-config.xml. I know that thre is tag withThis is the wrong place to configure a connection pool, too. Struts should have nothing to do with it. What if you change Web frameworks to WebWork or Spring? The connection pool should be configured in the container that hosts your app, not Struts.
this name, but the problem is i don't know how to use
this tag. If any budy know how to use this please
tell me the syntax or any example.
plese... reply soon..Don't do it. Think about doing it in your container, not Struts.
% -
How to use form name in struts html:form tag
Hi,
I want to validate text box value, if it is ordinary html form I would have done like this <form name="myform" action="xxxx.jsp" onsubmit="return validate()">
But am using struts html:form tags. In this case how can I use/specify name for a form.
Can any one help me.
ThanksThe name of the form comes from the actionForm you have defined backing it.
View source on the generated page to see what HTML it constructs.
You are able to use the onsubmit event with the <html:form> tag just like the standard one, so if all you want to do is that:
<html:form action="/saveUser" onsubmit="return validate()">
...You can also give it a styleId, which will generate an id in the HTML.
See the tag documentation for details: http://struts.apache.org/1.2.x/userGuide/struts-html.html#form -
How to use nested tag in Struts
Hi..
Can any one guide me how to use nested tag in Struts. So far i already tried bean tag with no error but when i try to use nested tag i got error like
javax.servlet.ServletException: Cannot find bean: "" in any scope
Below are my class:
action class
session.setAttribute ("MyDetailList", detailList);
JSP page
<logic:iterate id="list" name="MyDetailList">
Company ID : <bean:write name="list" property="companyID" />
</logic:iterate>
For bean tag, i got no error at all and below are my code for nested tag
action class
session.setAttribute ("MyDetailList", detailList);
JSP Page
<nested:nest property="MyDetailList">
Make : <nested:text property="make"/>
Car ID : <nested:text property="carID"/>
</nested:nest>
When i run the code, i got error message
javax.servlet.ServletException: Cannot find bean: "" in any scope
Any body can help me?
zulwhat am I doing wrong?You will notice above that I mentioned
YOU CAN'T USE CUSTOM TAGS AS ATTRIBUTES TO OTHER CUSTOM TAGS
(was that loud enough for you to notice this time)?
Try
<html:text styleId="instruction" styleClass="text" size="50" name="instruction" property="value"/>
//or
<html:text styleId="instruction" styleClass="text" size="50" property="instruction" value="<%= instruction.getValue() %>"/>
better alternative: populate your formbean with your action and just have:
<html:text styleId="instruction" styleClass="text" size="50" property="instruction"/>
If you set the "instruction" property of your formBean in the action, the value will be automagically reflected here.
Cheers,
evnafets
Maybe you are looking for
-
Hi Everyone, We have the password portal up and running on one box and another server with FIM R2 and SharePoint 2010. All is good with the exception that our end users typically get distracted during the password registration and/or reset process a
-
Can't download itunes on Windows 7
I can download and install other software, but when I attempt to download iTunes, I receive the 'where do you want to save the installer' dialog, and then nothing. No download, no installer, I just go straight to the 'Thank you for installing' page.
-
Place file in central instance(AIX/UNIX) from Application server in Windows
Hi guys, We have the central instance running in AIX and app servers in AIX/UNIX as well. now we want to replace the app server by windows server. so central instance remain as AIX/unix server and app server becomes Windows NT. then how can i place a
-
Connecting Creative 5.1 Speakers to my MacBook
Hi, I'm new to Apple and just got a MacBook. How can I connect my Creative 5.1 Speakers to my new MacBook? What accessories do I need if the MacBook natively supports this or is there an external sound card that is compatible? Cheers
-
Movie on iPad won't open on airplane
The problem we have encountered occurs when we travel. Before we leave home we rent movies on our computer and transfer to our iPad or directly to our iPad (have tried both ways) be viewed while we are on the airplane. However, when we try to play th