Vous êtes sur la page 1sur 3

Create dynamic project ->Project Name : SampleStruts -> next ->next-> check mark on (Generate

web.xml deployment ) ->Finish

Goto -> Webcontent folder -> right click -> New-> create JSP file -> File name = index.jsp ->next->Finish

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:form action="sayhello">
<s:textfield name="name" label="Enter your Name :"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form>
</body>
</html>

We have to copy the jar files list

 Commons-io-1.3.2 jar
 Commons –fileupload-1.2.1 jar
 Commons –lang-2. Jar
 Commons-logging-1.0.4 jar
 Commons-logging-api 1.1 jar
 Freemarker 2.3.18 jar
 Javassist-3.0.4 jar
 Ognl-3.0.4 jar
 Struts2-core 2.3.1.2 jar
 Xwork-core 2.3.1.2 jar

Goto web.xml file write as seeing below :

<?xml version="1.0" encoding="UTF-8"?>


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>SampleStruts</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>Struts2</filter-name>
<filter-
class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-
class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

Create struts.xml file

Goto -> java Resources -> src->right click-create folder name (resources) right click ->new ->other ->goto
xml folder -> click XMLfile ->next -> File name=struts.xml ->net->next ->finish.

<?xml version="1.0" encoding="UTF-8"?>


<!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="sayhello" class="com.seconds.sayhello" method="execute">
<result name="success">welcome.jsp</result>
</action>
</package>
</struts>

Create .java class file Ex: sayhello.java

Goto java resource -> src-> right click create java class ->write package name and name ->finish.
=com.seconds.sayhello

package com.seconds;

public class sayhello {


private String name;

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}
public String execute()
{
return "success";
}

}
Create welcome.jsp page con Webcontent folder -> right click -> create jsp page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
My name is :<s:property value="name"/>
</body>
</html>

Vous aimerez peut-être aussi