Creating a struts project using Eclipse Ganymede
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 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. ]
TechcubeTalk Staff
Latest posts by TechcubeTalk Staff (see all)
- Workshop: Developing a personal mini Photo Gallery application using Struts2, Hibernate and MySQL BLOB – Part 1 (developing admin panel) - May 12, 2013
- Step by step auto code generation for POJO domain java classes and hbm using Elipse Hibernate plugin - April 23, 2013
- Workshop on Creating a Personal MusicManager Web Application with Struts2, Hibernate and MySQL - April 22, 2013















Oct 06, 2011 @ 04:29:35
Hey, from slide number 5, you mention struts.jar. Is this a Struts 1 thing or Struts 2? As far as I can tell, Struts 2 provides many JARs (“struts2-core,” “struts2-codebehind…”). -Parker