有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

html调用中的java函数。回答表单时使用jsp

我有一本书。jsp文件是一个基本的聊天机器人,该页面被设计为一个div,它应该保存从表单中产生或获得的消息。 表单有一个输入行,用于保存消息

我想调用另一个java函数。仅在提交表单后才从div中删除java文件

<div id="wrapper">
    <div id="menu">
        <p class="welcome">Welcome, <b>
         <%
                if (ctx.isLoggedIn()) //if there is someone in the current session
                {
                    String name = ctx.getName(); // puts the name in the page
                    out.write(name); // same as last row
                }
        %></b></p>
        <p class="logout"><a id="exit" href="#">Exit Chat</a></p>
        <div style="clear:both"></div>
    </div>

    <div id="chatbox" style="overflow-y: scroll;">
    <%
        //the place I want to call the function
     %>
    </div>

    <form name="message" action="#" method="post">
        <input name="usermsg" type="text" id="usermsg" size="63" oninput="buttonEnabled()"/>
        <input name="submitmsg" type="submit"  id="submitmsg"/>
    </form> <!-- the form that is served -->
</div>

ctx定义为我创建的类中的对象

Context ctx = new Context(pageContext);

我试着这样调用函数-

<%
if(request.getParameter("usermsg").toString().length() > 0)// not empty
    out.write(ctx.handleMessages());
%>

但由于某种原因,它没有起作用

函数handleMessages()有一个队列,其中包含来自服务器和客户端的所有消息,并返回一个已生成为HTML代码的String

returnedMsg += "<b>"+message.getUser()+"</b> - <a style='color:gray;'>"+message.getTime()+"</a>";
        returnedMsg += "<br>";
        returnedMsg += "<a>"+msg.getText()+"</a>";
        returnedMsg += "<hr>";

所以每个聊天信息都应该是这样的-

how the chat should look

如果有人知道在提交表单时如何从该div调用handleMessages(),这将对我非常有帮助

谢谢,就在前面


共 (0) 个答案