<display:table name=”mainlist” id=”par” export=”true” requestURI=”/action.do” style=”border: 1px solid #CCCCCC;”>
<display:column property=”parameter” title=”Parameter” />
<display:column property=”parameter” title=”Parameter” />
</display:table>
21 Jul
Using display tag
29 Jun
Using nested logic:iterate
20 Jun
Using logic iterate in jsp.
Bean should be available to Jsp via request or session
<logic:iterate name=”beanName”>
<bean:write name=” beanName” property=”propertyName1” />
<bean:write name=” beanName” property=”propertyName2” />
<bean:write name=” beanName” property=”propertyName3” />
</logic:iterate>
29 May
Loading html:select options with collection
Beanname is bean containing name,value pair, that should be in request or session scope.
<html:optionsCollection name=”beanname” label=”name” value=”value” />
29 Apr
Form submission with multiple text box with same name
Input.Jsp:
<html:form action=”/actionName” method=”post”>
Parameter1:<html:text property=”parameter1″></html:text>
Parameter2:<html:text property =”Parameter1″> </html:text>
Parameter3:<html:text property =”Parameter1″> </html:text>
<html:submit value=”submit”></html:submit> | <html:reset value=”Cancel” </html:reset >
</html:form>
ParameterForm.java
public class ParameterForm extends ActionForm {
String[] parameter1;
Setter, getter function of parameter1
}
ExampleAction.java
public class ExampleAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ParameterForm parameterForm = (ParameterForm) form;
String[] parameter = parameterForm.getParameter1();
String parameter1 = parameter [0];
String parameter2 = parameter [1];
String parameter3 = parameter [2];
/* JDBC code to insert into database */
}
}
1 Mar
Configuring Struts with Ibatis
Need following following jars: Ibatis-db , commons-dbcp, dom4j, jta
Java class for connection
import com.ibatis.db.sqlmap.SqlMap;
import java.io.Reader;
import com.ibatis.db.sqlmap.XmlSqlMapBuilder;
import com.ibatis.common.resources.Resources;
public class Connection {
private static SqlMap sqlMap=null;
static{
try{
String resource=”ibdb/connection.xml”;
Reader reader=Resources.getResourceAsReader(resource);
sqlMap=XmlSqlMapBuilder.buildSqlMap(reader); }
catch (Exception e)
{System.out.println(“exception: “+e);
throw new RuntimeException(
“Error initializing Connection class. Cause: ” + e);
}
}
public SqlMap getConnection(){
return sqlMap;
}
}
Connection.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE sql-map-config PUBLIC “-//iBATIS.com//DTD SQL Map Config 1.0//EN” <“http://www.ibatis.com/dtd/sql-map-config.dtd”>
<sql-map-config>
<properties resource=”ibdb/connection.properties” />
<settings maxExecute=”400″ maxExecutePerConnection=”5″ maxTransactions=”30″ <statementCacheSize=”150″ />
<datasource name=”basic” default = “true” factory-class=”com.ibatis.db.sqlmap.datasource.DbcpDataSourceFactory”>
<property name=”JDBC.Driver” value=”com.mysql.jdbc.Driver”/>
<property name=”JDBC.ConnectionURL” value=”jdbc:mysql://localhost/databasename?autoReconnect=true”/>
<property name=”JDBC.Username” value=”root”/>
<property name=”JDBC.Password” value=”mysql”/>
<property name=”Pool.MaximumActiveConnections” value=”1″/>
<property name=”Pool.MaximumIdleConnections” value=”1″/>
<property name=”Pool.MaximumWait” value=”60000″/>
</datasource>
<sql-map resource=”/ibdb/query.xml” / >
</sql-map-config>
28 Jan
Form submission in Struts
Input.Jsp:
<html:form action=”actionName” method=”post”>
parameter1:<html:text property=”parameter1″ />
parameter2:<html:text property=”parameter2″/>
<html:submit></html:submit><html:reset></html:reset>
</html:form>
Struts-config.xml:
<form-bean>
<form-bean name=”parameterForm” type=”ParameterForm”/>
</form-bean>
<action-mappings>
<action
attribute=”parameterForm”
name=”parameterForm”
input=”/input.jsp”
path=”/actionName”
scope=”request”
type=”ExampleAction”
<forward name=”success” path=”/Success.jsp”/>
<forward name=”failure” path=”/Failure.jsp”/>
</action>
</action-mappings>
ParameterForm.java
public class ParameterForm extends ActionForm {
String parameter1;
String parameter2;
Setter, getter function of parameters
}
ExampleAction.java
public class ExampleAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ParameterForm parameterForm = (ParameterForm) form;
String parameter1 = parameterForm.getParameter1();
String parameter2 = parameterForm.getParameter2();
/* JDBC code to insert into database */
}
}