About the use of IncludeAction in struts
I am just trying to use include action class in struts, but i am not able to do....the steps i did are as follows
step 1 : first I created the presentation page, which is
Welcome.jsp
<%@ taglib uri="http://struts.apache.org/tags-bean" pre开发者_JAVA百科fix="bean"%>
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div align="center">
<bean:include id="bid" forward="logins" />
</div>
</body>
</html>
step2: then I created servlet class, from where I passed msg in another client page
ShowServlet.java
package com.ashish.struts.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ashish.struts.LoginForm;
public class ShowServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException
{
System.out.println("Now I m in Servlet Class!!!!");
String msg="This is your Login page";
request.setAttribute("MSG", msg);
RequestDispatcher rd= request.getRequestDispatcher("/index1.jsp");
rd.forward(request, response);
}
}
index1.jsp
<%@ page isELIgnored="false" %>
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div align="center">
${MSG }
</div>
</body>
</html>
step3: then finally i configured the struts-config.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="log" type="com.ashish.struts.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="logins" path="/logs1.do" />
</global-forwards>
<action-mappings >
<action path="/logs1" name="log" type="org.apache.struts.actions.IncludeAction" parameter="/WEB-INF/classes/com/ashish/struts/servlet/ShowServlet" />
</action-mappings>
<message-resources parameter="com.ashish.struts.ApplicationResources" />
</struts-config>
is there any things wrong i did , in the above steps or i left some things to do .....
because whenever i run this application , no error is showing , but desired output is not coming...
Can any one give the answer for that ...
Thanks Ashish....
You have to add <bean:write name="bid" />
in Welcome.jsp at the location where you want to display it.
Note: all <bean:include id="NAME"... />
should have an accompanying <bean:write name="NAME" />
to print the output message.
精彩评论