Here is a short article that may help you while creating a struts project in Eclipse’s latest 3.30 i.e Ganymede. Please follow the following steps :
1 . Create a Dynamic Web Project
2. Configure the Web Project
3. Configuration Continues….
4. The project looks like the following :
5. Put the following Jars to Project Build Path
You can download these struts distribution from http://archive.apache.org/dist/jakarta/struts/
6. Now create the packages for actions and forms as shown in the image below
7. Here is the listing for the web.xml
Web.xml
xml version=“1.0″ encoding=“UTF-8″?>
8. Then the listing for struts-config.xml . Put this file under WEB-INF as mentioned in web.xml
Struts-config.xml
xml version=“1.0″ encoding=“ISO-8859-1″ ?>
9. Here comes our action class NewAction.java. Please be careful about package name.
|
package com.deb.struts.actions;
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.deb.struts.forms.NewForm;
publicclass NewAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse resp)
{
NewForm nf = (NewForm)form;
req.setAttribute(“NAME”, nf.getName());
return mapping.findForward(“valid”);
}
}
|
10……. and the action form bean
NewForm.java:
|
package com.deb.struts.forms;
import org.apache.struts.action.ActionForm;
publicclass NewForm extends ActionForm{
/**
*
*/
privatestaticfinallongserialVersionUID = 1L;
private String name =null;
public String getName() {
returnname;
}
publicvoid setName(String name) {
this.name = name;
}
}
|
11. Here are the two JSPs
The login.jsp
DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
_____________________________
12. Finally Your project looks like the following
13 . Now, you can build and deploy the project to a Server.
14. Once deployed hit the login.jsp page
The page shown above appears.
Enter some text in the text box as shown below
Click on the ‘Submit Query’ button.
Then this page should appear…..
This confirms that you have successfully created and deployed your struts project .
Happy Coding
[The Author Deb Kumar Basu is working as a Consultant in a leading MNC. He has provided great tips on how to use the latest version of Eclipse Ganymede to develop struts applications smoothly. If you want to develop struts projects but do not want to use RAD or WSAD from IBM due to cost then this is a solution for you.
The Author is always looking for simple inexpensive solutions for J2EE development. If you need more information on this please touch base with the Author through comment in the article. ]
Related Articles:
- File upload to BLOB field and display attachment dialog box Sometimes a developer needs to provide the feature in their...
- Eclipse DemoCamp starts from Nov 01 From this November 01 till December 04, Eclipse community is...












You can subscribe by e-mail to receive news updates and breaking stories.