Struts Examples
Steps to Execute Jsp |
Steps to Execute Struts |
Struts Module
|
|
| Step 1:Here is the code for(ProLogin.jsp) User Request Page |
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<html:html>
<html:form method="POST" action="/pro">
Enter your Project Code :
<html:text property="procode"></html:text>
<br>
<br>
<br>
<html:submit value="Get ProjectDetails" property="submit"></html:submit>
<br>
<br>
</html:form>
</html>
|
 |
| Step 2:Here is the code for(ProForm.java)FormBean class |
package com.yourcompany.struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class ProForm extends ActionForm
{
private String proclilocation;
private String proname;
private String prodescription;
private String procode;
private String proenvironment;
private String procliname;
public String getProclilocation()
{
return proclilocation;
}
public void setProclilocation(String proclilocation)
{
this.proclilocation = proclilocation;
}
public String getProname()
{
return proname;
}
public void setProname(String proname)
{
this.proname = proname;
}
public String getProdescription()
{
return prodescription;
}
public void setProdescription(String prodescription)
{
this.prodescription = prodescription;
}
public String getProcode()
{
return procode;
}
public void setProcode(String procode)
{
this.procode = procode;
}
public String getProenvironment()
{
return proenvironment;
}
public void setProenvironment(String proenvironment)
{
this.proenvironment = proenvironment;
}
public String getProcliname()
{
return procliname;
}
public void setProcliname(String procliname)
{
this.procliname = procliname;
}
public void reset(ActionMapping mapping, HttpServletRequest request)
{
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
return null;
}
}
|
| Step 3:Here is the code for(ProAction.java) request handled by the Action class
|
package com.yourcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.ProForm;
import java.sql.*;
import java.util.*;
import javax.servlet.http.*;
import com.yourcompany.struts.ProVo;
public class ProAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ProForm proForm = (ProForm) form;
String procode=proForm.getProcode();
Connection con=null;
ResultSet rs=null;
Statement st=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vijikumar","root","sun");
st=con.createStatement();
HttpSession ses=request.getSession();
String sql="select * from prodb where procode='"+procode+"'";
rs=st.executeQuery(sql);
ArrayList result=new ArrayList();
while(rs.next())
{
projectvo record=new projectvo();
record.setProcode(rs.getString("procode"));
record.setProname(rs.getString("proname"));
record.setProcliname(rs.getString("procliname"));
record.setProclilocation(rs.getString("proclilocation"));
record.setProdescription(rs.getString("prodescription"));
record.setProenvironment(rs.getString("proenvironment"));
result.add(record);
}
ses.putValue("valuesss",result);
}
catch(Exception e)
{
System.out.println("****************");
System.out.println(e.getMessage());
}
if(procode!=null)
{
return mapping.findForward("prowin");
}
else
{
return mapping.findForward("prolose");
}
}
}
|
| Step 4:Here is the code for(ProVo.java)Result (view)bean class |
package com.skdotcom.struts.form;
public class projectvo {
private String proname;
private String procode;
private String procliname;
private String proclilocation;
private String proenvironment;
private String prodescription;
public String getProclilocation() {
return proclilocation;
}
public void setProclilocation(String proclilocation) {
this.proclilocation = proclilocation;
}
public String getProcliname() {
return procliname;
}
public void setProcliname(String procliname) {
this.procliname = procliname;
}
public String getProcode() {
return procode;
}
public void setProcode(String procode) {
this.procode = procode;
}
public String getProdescription() {
return prodescription;
}
public void setProdescription(String prodescription) {
this.prodescription = prodescription;
}
public String getProenvironment() {
return proenvironment;
}
public void setProenvironment(String proenvironment) {
this.proenvironment = proenvironment;
}
public String getProname() {
return proname;
}
public void setProname(String proname) {
this.proname = proname;
}
}
|
| Step 5:Here is the code for(ProView.jsp)to display the result Page |
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
prefix="logic" %>
<html:html>
<body>
<div align="center">
<center>
<table border="3" bgcolor="#00ffff" align="center">
<td ><font color="#008000"><b> Project
Code :</b></font></td>
<td><font color="#008000"><b> Project
Name :</b></font></td>
<td ><font color="#008000"><b> Proclient
name: </b></font></td>
<td ><font color="#008000"><b> proclilocation:
</b></font></td>
<td ><font color="#008000"><b> ProEnvironment:</b></font></td>
<td ><font color="#008000"><b> ProDescription:</b></font></td>
</tr>
<logic:iterate id="res" scope="session"
name="valuesss">
<tr>
<td ><font color="#008000"><b><bean:write
name="res" property="procode"/></b></font></td>
<td><font color="#008000"><b><bean:write
name="res" property="proname"/></b></font></td>
<td ><font color="#008000"><b><bean:write name="res" property="procliname"/></b>
</font></td>
<td ><font color="#008000"><b> <bean:write name="res" property="proclilocation"/></b>
</font></td>
<td ><font color="#008000"><b> <bean:write name="res" property="proenvironment"/></b>
</font></td>
<td ><font color="#008000"><b><bean:write name="res" property="prodescription"/></b>
</font></td>
</tr>
</logic:iterate>
</table>
</center>
</div>
</body>
</html:html>
|
 |
|
Back to Top |