简体   繁体   English

JSP将数据发送到Java类

[英]JSP send data to Java class

I'm looking to send information after each link click to my java class to help increment a counter and to change an object which is held in my bean (myGame) which holds an array of 'cases'. 我希望在每次链接单击到我的java类后发送信息,以帮助增加计数器并更改保存在我的bean(myGame)中的对象,该bean保存“案例”数组。 I understand that I can increment a counter using JS, but i'd like to keep all game logic within the bean if possible. 我知道我可以使用JS来增加计数器,但我想尽可能将所有游戏逻辑都保留在bean中。
I have considered using forms and changing the anchor to a submit button, however, I'd like to keep that the player can no longer click the link after it the case is eliminated. 我已经考虑过使用表格并将锚点更改为“提交”按钮,但是,我想避免这种情况发生后,播放器无法再单击链接。
The printCase(int) function works by finding the corresponding case in the array, checking the value of a boolean (is the case is eliminated from the game [deal or no deal]) and then prints the amount of money held in the case if eliminated; printCase(int)函数的工作原理是在数组中找到相应的大小写,检查布尔值(该大小写是否从游戏中消除了[交易或无交易]),然后打印出该情况下持有的金额淘汰 the case number if it is not. 案例编号(如果不是)。

I have about a dozen cases. 我有十几个案例。

<jsp:useBean id="myGame" scope="session" class="dealOrNoDeal.GameLogic"/>
<table border="1" id="dndTable">
    <form action="/../doStuff.jsp" method="post">
        <tr>
            <td> <%= myGame.printCase(0) %> </td>
        </tr>
    </form>
</table>  

I've also considered changing my bean to a servlet. 我还考虑过将bean更改为servlet。 Does that work? 那样有用吗? Can you have a bean in a servlet? 您可以在Servlet中使用Bean吗?
Thanks all. 谢谢大家

Update: I've made printCase now print the tag that it's within now, as well. 更新:我已经使printCase现在也可以打印其中的标签。 Prints as a submit button if the case is not opened, prints as a <p> if it is (I need it to use the class). 如果未打开外壳,则将其打印为提交按钮;如果未打开,则将打印为<p> (我需要使用它来使用该类)。 Attempted putting the <td> s in there as well, but it somehow messes up the formatting. 也尝试将<td>放入其中,但是以某种方式弄乱了格式。
I'm now looking to get the name of the one button that was clicked, any ideas? 我现在正在寻找被单击的一个按钮的名称,有什么想法吗?

I'm not sure about understand completely your qestion. 我不确定要完全了解您的问题。 But i'll try: 但我会尝试:

U have 2 ways: 您有2种方法:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM