STEP1: Create a “dynamic web project ” Named “JSPSample”
STEP 2: Create a new JSP File Named “Init.jsp” under WebContent folder..
< %@ page language="java" contentType="text/html" % >
< %!
public void jspInit() {
ServletConfig sConfig = getServletConfig();
String emailAddr = sConfig.getInitParameter("email");
ServletContext ctx = getServletContext();
ctx.setAttribute("mail", emailAddr);
}
% >
< %= application.getAttribute("mail") % >
STEP 3: Include below code in a Xml file “web.xml” under WEB-INF folder
< welcome-file-list >
< welcome-file >Init.jsp< /welcome-file >
< /welcome-file-list >
< servlet >
< servlet-name > Init < /servlet-name >
< jsp-file >/ Init.jsp < /jsp-file >
< init-param >
< param-name >email< /param-name >
< param-value >[email protected]< /param-value >
< /servlet >
< servlet-mapping >
< servlet-name > Init < /servlet-name >
< url-pattern >/ Init.jsp < /url-pattern >
< /servlet-mapping >
STEP 4: Export the project” JSPSample” into a War File named ” JSPSample.war” and place it in the deploy folder of JBOSS server.
STEP 5:To see the Output use this url ” http://localhost:8080/ JSPSample /Init.jsp ”,where JSPSample is the .war file name and Init.jsp is specified in the < welcome-file >of web.xmlfile.
Step 6: Output is given below
[email protected]
STEP 2: Create a new JSP File Named “Init.jsp” under WebContent folder..
< %@ page language="java" contentType="text/html" % >
< %!
public void jspInit() {
ServletConfig sConfig = getServletConfig();
String emailAddr = sConfig.getInitParameter("email");
ServletContext ctx = getServletContext();
ctx.setAttribute("mail", emailAddr);
}
% >
< %= application.getAttribute("mail") % >
STEP 3: Include below code in a Xml file “web.xml” under WEB-INF folder
< welcome-file-list >
< welcome-file >Init.jsp< /welcome-file >
< /welcome-file-list >
< servlet >
< servlet-name > Init < /servlet-name >
< jsp-file >/ Init.jsp < /jsp-file >
< init-param >
< param-name >email< /param-name >
< param-value >[email protected]< /param-value >
< /servlet >
< servlet-mapping >
< servlet-name > Init < /servlet-name >
< url-pattern >/ Init.jsp < /url-pattern >
< /servlet-mapping >
STEP 4: Export the project” JSPSample” into a War File named ” JSPSample.war” and place it in the deploy folder of JBOSS server.
STEP 5:To see the Output use this url ” http://localhost:8080/ JSPSample /Init.jsp ”,where JSPSample is the .war file name and Init.jsp is specified in the < welcome-file >of web.xmlfile.
Step 6: Output is given below
[email protected]
This post first appeared on Every Day Of Your Life Is A Page Of Your History, please read the originial post: here