Java 如何在struts2中查看数据?
我正试图从jsp查看数据库中的数据,所以现在我提出了一个想法,在jsp中没有任何scriplet或Java代码。我已经学习了struts.xml中使用的模型驱动和一些拦截器,但我不知道如何实现它。因此,如果我是strut2世界的新手,是否可以有人来指导和帮助我更进一步 Beantest: DataAction.java: Actiontest.java Bookview.jsp: web.xml: strut2.xml 不要在JSP中使用s:action标记,除非您知道如何以及为什么这样做。要在JSP中显示值,根本不需要它。您应该使用struts标记来访问ActionBean属性。例如,您可以使用s:property标记将值打印到JSP输出。比如说Java 如何在struts2中查看数据?,java,jsp,struts2,Java,Jsp,Struts2,我正试图从jsp查看数据库中的数据,所以现在我提出了一个想法,在jsp中没有任何scriplet或Java代码。我已经学习了struts.xml中使用的模型驱动和一些拦截器,但我不知道如何实现它。因此,如果我是strut2世界的新手,是否可以有人来指导和帮助我更进一步 Beantest: DataAction.java: Actiontest.java Bookview.jsp: web.xml: strut2.xml 不要在JSP中使用s:action标记,除非您知道如何以及为什么这样做。要在
<s:iterator value="beans">
id: <s:property value="id"/><br>
Book: <s:property value="book"/><br>
Author: <s:property value="author"/><br>
Availbleqty: <s:property value="availbleqty"/><br>
Category: <s:property value="category"/><br>
<s:/iterator>
FilterDispatcher已弃用,您应将其替换为StrutsPrepareAndExecuteFilter。见文件。另请参见此答案
.在知道如何以及为什么这样做之前,不要在JSP中使用s:action标记。要在JSP中显示值,根本不需要它。您应该使用struts标记来访问ActionBean属性。例如,您可以使用s:property标记将值打印到JSP输出。比如说
<s:iterator value="beans">
id: <s:property value="id"/><br>
Book: <s:property value="book"/><br>
Author: <s:property value="author"/><br>
Availbleqty: <s:property value="availbleqty"/><br>
Category: <s:property value="category"/><br>
<s:/iterator>
FilterDispatcher已弃用,您应将其替换为StrutsPrepareAndExecuteFilter。见文件。另请参见此答案
.如下更改web.xml和stuts.xml Struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<package name="a" namespace="/" extends="struts-default">
<action name="" class="Action.ActionTest" method="viewbookaction">
<result name="success">/BookView.jsp</result>
</action>
</package>
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
就这些。只需运行。如下更改web.xml和stuts.xml Struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<package name="a" namespace="/" extends="struts-default">
<action name="" class="Action.ActionTest" method="viewbookaction">
<result name="success">/BookView.jsp</result>
</action>
</package>
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
就这些。只需运行。您可以使用struts2标记来显示数据,例如通过绑定Action中的数据来显示property标记感谢您的回复如果您有时间,请提供解决方案请查看任何S2教程。还有,你真的需要在这里使用标签吗?我不明白为什么。k很好,我只是在学习,但我不知道如何在不使用javacodeExact解决方案的情况下将值从xml传递到jsp参考您可以使用struts2标记来显示数据,例如通过绑定Action中的数据来显示属性标记感谢您的回复如果您有时间,请提供解决方案请查看任何S2教程。还有,你真的需要在这里使用标签吗?我不明白为什么.k很好,我只是在学习,但我不知道如何在不使用javacodeExact解决方案的情况下将值从xml传递到jsp。很好,先生,我将遵循,但它不能在jsp页面中显示一个值??我现在不知道为什么??JSP中的值在您调用一个操作并使用此JSP返回结果后将可用。先生,我使用方法名称method=viewbookaction调用了一个操作,结果页面是Bookview JSP viewbook方法返回的列表大小是多少?并从action类中删除ModelDriven,因为我在问题中没有看到它。Beantest@1e87539]好的,先生,我会跟随,但它不能在jsp页面中显示一个值??我现在不知道为什么??JSP中的值在您调用一个操作并使用此JSP返回结果后将可用。先生,我使用方法名称method=viewbookaction调用了一个操作,结果页面是Bookview JSP viewbook方法返回的列表大小是多少?并从action类中删除ModelDriven,因为我在问题中没有看到它。Beantest@1e87539]感谢你的努力,它没有显示结果,我将检查我的一方,并将在这里更新??感谢你的努力,它没有显示结果,我将检查我的一方,并将在这里更新??
<s:iterator value="beans">
id: <s:property value="id"/><br>
Book: <s:property value="book"/><br>
Author: <s:property value="author"/><br>
Availbleqty: <s:property value="availbleqty"/><br>
Category: <s:property value="category"/><br>
<s:/iterator>
<struts>
<constant name="struts.devMode" value="true" />
<package name="a" namespace="/" extends="struts-default">
<action name="" class="Action.ActionTest" method="viewbookaction">
<result name="success">/BookView.jsp</result>
</action>
</package>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>