hi Guys!!!
I know
struts 1.3 but new in struts2 so i am creating hello world application on struts2 using eclipse(Indigo) with apache
tomcat 7
but get an error like
HTTP Status 404 - /struts2/
--------------------------------------------------------------------------------
type Status report
message /struts2/
description The requested resource (/struts2/) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.14
this is my struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="HelloWorld" class="com.controller.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
</struts>
this is my Action Support class
package com.controller;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport{
String message ;
String userName ;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String execute(){
setMessage("Hello " + getUserName()) ;
return "SUCCESS";
}
}
this is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>struts2</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.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
this is my index.jsp
<%@ 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="HelloWorld">
<s:textfield name="userName" label="User Name:"></s:textfield>
<s:submit/>
</s:form>
</body>
</html>
this is my hierarchy
|struts2
| |
Java Resources
| | |src
| | | | com.controller
| | | | | HelloWorld.java
| | |resources
| | | | struts.xml
| | build
| | WebContent
| | |WEB_INF
| | | | lib
| | | | | web.xml
| | |index.jsp
| | |success.jsp
Pl help me out
Regards
Ishant
Software Engineer