Loading...
Saturday, October 10, 2015

Struts2 Example Display Different Type Property

Struts2 Example Display Different Type and how to apply css class name
Here input  using html tag . value =   ${name } css class name  Class="form-control" in html tag

Here input  using struts2 tag . value =  %{name }




index.jsp

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

<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>index</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body background="java9r.png">


<div class="container">
<div align="center"><label >Struts2 Example Display Different Type</label></div>
<form action="sample">
<div class="form-group">
<label>Name:</label>
<s:textfield cssClass="form-control" name="name" ></s:textfield>
</div>
<div class="form-group">
<s:submit cssClass="btn btn-default" value="Send"></s:submit>
</div>
</form>
</div>


</body>
</html>

struts.xml

<struts>



<package extends="struts-default" name="abc" namespace="/">
<action class="java9r.com.Sample" name="sample">

<result name="success">Success.jsp</result>

</action>


</package>
</struts>


Sample.java

package java9r.com;



public class Sample {
private String name;

public String getName() {
return name;
}

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

public String execute(){


return "success";



}


}


success.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html ">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success</title>

<link rel="stylesheet" href="css/bootstrap.min.css">


</head>
<body background="java9r.png">
<div class="container">
<div align="center"><label >Struts2 Example Display Different Type and how to apply css class name </label></div>
here input using html tag . value = <code> ${name }</code> css class name Class="form-control" in html tag<br>
<input Class="form-control" type="text" value="${name }"><br>

here input using struts2 tag . value = <code>%{name }</code> <br>
<s:textfield Class="form-control" value="%{name}"></s:textfield>css class name cssClass="form-control" in Struts2 tag<br>

here showing how to display the values in property <code><s:property value="name"/></code><br>

-----------------%{name } ----------------------<br>

+++++++++++++++<s:property value="name"/>++++++++++++++++++++



<br>
</div>

</body>
</html>
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>Java9r</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>

Output


0 comments:

Post a Comment

 
TOP