First Struts 2 Application

Tagged:  

File Heirarchy

File Heirarcy

 

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
   <s:form action="AddEntry">
   <s:textfield label="Name" name="name"/>
   <s:textfield label="Address" name="address"/>
   <s:textfield label="Phone Number" name="phoneNumber"/>
   <s:submit value="ADD"/>
   </s:form>
</body>
</html>

 

success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Successfully displayed in console.
</body>
</html>

 

AddEntry.java

package phoneBook;
import com.opensymphony.xwork2.ActionSupport;

public class AddEntry extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private String name = null;

	private String address = null;
	private String phoneNumber = null;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;

	}
	public String getAddress() {
		return address;

	}
	public void setAddress(String address) {
		this.address = address;

	}
	public String getPhoneNumber() {
		return phoneNumber;

	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;

	}
	
	public String execute() throws Exception{
		System.out.println("Name\t\t:" +name);

		System.out.println("Address\t\t:" +address);
		System.out.println("Phone Number\t:" +phoneNumber);

		return SUCCESS;
	}
}

 

struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="default" extends="struts-default">
        <action name="AddEntry" class="phoneBook.AddEntry">
            <result>/success.jsp</result>
        </action>
    </package>
</struts>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

 

jar files:

  • commons-logging-1.0.4.jar
  • freemarker-2.3.8.jar
  • ognl-2.6.11.jar
  • struts2-core-2.0.11.jar
  • xwork-2.0.4.jar

 

html page:

output

console:

console output

ASK

HTTP Status 404 - /Hello_Struts2_1/AddEntry

--------------------------------------------------------------------------------

type Status report

message /Hello_Struts2_1/AddEntry

description The requested resource (/Hello_Struts2_1/AddEntry) is not available.

code works.... very nice for a beginner like me

I done the above code and i got
HTTP Status 404 -
The requested resource is not available.

che (Tomcat/6.0.29 any idea in jdk1.6).
is it necessary Compile addEntry.java

what did you use to program J2EE? What Netbean or Eclips?

i prefer eclipse (Galileo) yusuf......

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.