关于struts中IncludeAction的使用
我只是想在struts中使用include操作类,但我无法做到......我所做的步骤如下
步骤1:首先我创建了演示文稿页面,即
Welcome.jsp
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div align="center">
<bean:include id="bid" forward="logins" />
</div>
</body>
</html>
步骤2:然后我创建了servlet 类,从我在另一个客户端页面
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>
中传递消息的位置第3步:最后我配置了 struts-config.xml 文件,
<?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>
我在上面的步骤中做错了什么,或者我留下了一些事情要做.....
因为每当我运行此应用程序时,都不会显示错误,但没有出现所需的输出...
任何人都可以给出答案...
谢谢 阿希什……
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" prefix="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....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 Welcome.jsp 中要显示它的位置添加
。注意:所有
都应该有一个附带的
打印输出消息。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.