Thursday, August 16, 2012

Struts 2 hello world example


Open the Eclipse


Creating new dynamic web project


Give some name for the project. And set the target run time server


 Select the check box to  auto generate web.xml



Welcome.java

package com.jsl.struts2;
public class Welcome {
            private String username;
             public String execute(){
                                    return "success";
             }
            public String getUsername() {
                        return username;
            }
            public void setUsername(String username) {
                        this.username = username;
            }
}

Web.xml



  welcome

  
      index.jsp
   

  
      struts2
      org.apache.struts2.dispatcher.FilterDispatcher
  

  
      struts2
      /*
  


index.jsp

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

<%@taglib uri="/struts-tags" prefix="s" %>
<!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="hello">
                                    <s:textfield name="username" label="Enter User Name"/>
                                    <br>
                                    <s:submit value="Enter"/>
                        </s:form>
</body>
</html>

welcome.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>

<!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>
                        <h1>Hi! welcome to struts2world : <s:property value="username"/> </h1>
</body>
</html>





No comments:

Post a Comment

Spring Boot 3 : JWT with SecurityFilterChain, AuthorizeHttpRequests, RequestMatchers

pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"...