How to Make Java Struts
The proficiency, productivity, platform portability and security of Java make it the ideal technology for network computing and Web development projects, such as Apache Struts integration and execution. Java is found everywhere, from laptops to data centers, mobile phones to the Internet, and gaming systems to state-of-the-art supercomputers. Java integrates well with the Apache Struts Project, which is why the latter is the most recognized Web application framework for Java.
Instructions
-
-
1
Input the code below to create a JSP file and name it logon.jsp. This form illustrates the effect of Struts Action Framework with your HTML and JSP elements, particularly the form-handling portion:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<head>
<title>
<bean:message key="logon.title"/>
</title>
</head>
<body bgcolor="white">
<html:errors/>
<html:form action="/logon" focus="username">
<table border="0" width="100%">
<tr>
<th class="right">
<bean:message key="prompt.username"/>
</th>
<td class="left">
<html:text property="username" size="16"/>
</td>
</tr>
<tr>
<th class="right">
<bean:message key="prompt.password"/>
</th>
<td class="left">
<html:password property="password" size="16"/>
</td>
</tr>
<tr>
<td class="right">
<html:submit>
<bean:message key="button.submit"/>
</html:submit>
</td>
<td class="right">
<html:reset>
<bean:message key="button.reset"/>
</html:reset>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
-
2
Paste the code below to transfer data from an ActionForm to a business object:
PropertyUtils.copyProperties(actionForm, businessObject);
Reverse the parameters if you instead want to to transfer data from a business object to an ActionForm:
PropertyUtils.copyProperties(businessObject, actionForm);
-
-
3
Input the code to create your presentation page with the struts-html tag library. This file will serve as your multipart form:
<%@page language="java">
<%@taglib
uri="/WEB-INF/struts-html.tld"
prefix="html">
<html:form action="uploadAction.do" enctype="multipart/form-data">
Please Input Text: <html:text property="myText">
Please Input The File You Wish to Upload: <html:file property="myFile">
<html:submit />
</html:form>
-
4
Paste the following code to your Struts project to create your ActionForm bean. This FormFile will execute your action class and retrieve the information for your Struts project:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class UploadForm extends ActionForm {
protected String myText;
protected FormFile myFile;
public void setMyText(String text) {
myText = text;
}
public String getMyText() {
return myText;
}
public void setMyFile(FormFile file) {
myFile = file;
}
public FormFile getMyFile() {
return myFile;
}
}
-
1
Tips & Warnings
Join discussion forums to seek expert advice from master users of the Apache language and Java technology. Try doing as many tutorials as you can for these languages to gain basic knowledge about them.
References
Resources
- Photo Credit Jupiterimages/Pixland/Getty Images