Hi All,
I am very new to struts, know little java and some jsp.. so kindly be patient with me.
I work for a company who create software and sells it, but since business was down, so they laid of people. Now we have got a requirement which if we accomplish will give us business back and thus we will able to hire peopl back. but for making this requirement, I have to follow same archiecture that they have provided and accomplish it..
they use java/struts/jsp/weblogic6.
1 in this software..unfortutanely i don't know anything about struts and right now i have to deliver this by tomorrow. So I need help from you experts accomplishing this..
I have to design a jsp page which has some commands dropdown (should come from sybase db). I have a table defined..
I don't know how to design a jsp using struts tags etc and how to follow their architcure..
hope u guys can help me while I will provide you max information what is going on here..
I have a jsp now called listCommands.jsp and I have a struts-config.xml called
admin-struts-config.xml
when somebody hit listCommands.jsp -- it should go to some class -- establish a jdbc conn, get the values of dropdown and print it..
in admin-struts-config.xml, I have as below:
<action path="/command"
type="com.citi.soft.struts
.action.co
mmands.Com
mandAction
"
scope="request"
validate="false">
<forward name="listCommands" path="/jsp/admin/dev/listC
ommands.js
p" />
</action>
and in listCommands.jsp, right now I have:
<%@ taglib uri='struts/bean-el' prefix='bean' %>
<%@ taglib uri='struts/html' prefix='html' %>
<%@ taglib uri='struts/logic-el' prefix='logic' %>
<%@ taglib uri='jstl/c' prefix='c' %>
<!-- <form name="commandForm" action="/isoft/iSoft/Comma
ndServlet"
> -->
<html:form action="/command" method="post">
<table border='0' cellpadding='2' cellspacing='2'>
<tr>
<td>
<html:select styleClass="inputtextmediu
m" styleId="select5" property="test">
<html:option value="All">All</html:opti
on>
<html:options collection="UniqueKeyName"
property="code" labelProperty="codeDesc" />
</html:select>
</html:form>
and my CommandAction class looks as below:
package com.citi.soft.struts.actio
n.commands
;
import org.apache.struts.action.*
;
import org.apache.commons.beanuti
ls.*;
import org.apache.struts.action.*
;
import com.citi.soft.common.*;
import com.citi.soft.profile.*;
import com.citi.soft.reports.*;
import com.citi.soft.common.deleg
ator.*;
import com.citi.soft.util.logging
.*;
import com.citi.soft.util.email.*
;
import com.citi.soft.web.*;
import com.citi.soft.deals.*;
import com.citi.soft.struts.commo
n.* ;
import java.util.* ;
import java.net.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.DataSource;
import com.citi.soft.util.jndi.* ;
import com.citi.soft.struts.actio
n.* ;
import java.text.SimpleDateFormat
;
import com.citi.soft.reference.*;
public class CommandAction
extends Action {
private final static String BEANCLASS = "com.citi.soft.commands.Co
mmandsList
";
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("in CommandAction execute");
LogRecord m_lrec = new LogRecord();
Connection conn = null;
String keyName;
ArrayList UniqueKeyName = new ArrayList();
try
{
conn = ServiceLocator.getInstance
().getData
Source(com
.citi.soft
.common.sq
l.DataSour
ceName.SOF
TDLR.getNa
me()).getC
onnection(
);
Statement stmt = conn.createStatement();
String sql = "select * from iSoftKeyValueTb";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
keyName = rs.getString("keyname").tr
im();
System.out.println("KeyNam
e is : " + keyName);
m_lrec.add(MsgType.GEN, keyName);
ReferenceBean myref2 = new ReferenceBean();
myref2.setCode(keyName);
myref2.setCodeDesc(keyName
);
UniqueKeyName.add(myref2);
}
request.setAttribute("Uniq
ueKeyName"
,UniqueKey
Name);
}
catch(SQLException sqlEx) {
System.out.println("Except
ion is : "+ sqlEx);
sqlEx.printStackTrace();
ActionErrors errors = new ActionErrors();
ActionError error1 = new ActionError("errors.submit
report.rep
ort.error.
sql");
errors.add( ActionErrors.GLOBAL_ERROR,
error1 );
saveErrors( request, errors );
return actionMapping.findForward(
"failure")
;
}
finally {
try
{
conn.close();
}
catch (SQLException ignored)
{
}
}
return actionMapping.findForward(
"listComma
nds");
}
}
I have copied some stuff from here and there..
Can you please guide me how to accomplish this requirement.. how to make it work.. what else i am missing..
finally, when drop-down comes on page, there will be a submit button, which should send the chosen value from select list and should execute some commands, and bring the results back on a different frame (I will split the page in frames later)...
I know this is like teaching struts to me, but I want to learn and also meet my deadline, I will read the websites and books after I deliver this anyway, since if we accomplish this, we will able to bring our guys back as well as I will have learn .. for now, if you can help me, i would appreciate