当请求时,我如何从文本区域删除null.GetAttribute为null,以及如何从servlet修改标签的可见性

How can i remove the null from textarea when request.GetAttribute is null, and how can i modify the visibility of the label from the servlet

本文关键字:null 可见性 servlet 修改 标签 删除 请求 文本 区域 GetAttribute      更新时间:2024-06-08

请求时如何从文本区域中删除null。GetAttribute为null,如何从servlet修改标签的可见性?在输入文本区域上,它不显示request.getattribute值,在输出文本区域上它显示值,但当request.getattirbute为null时,null会打印在文本区域,我想删除它,怎么做?

    <label>Type word/s here:</label></br>
    <textarea name="Input" id="styleid">
    <%
    String msg=(String)request.getAttribute("Input");
    if(msg==null)
    {
        msg="";
    }
    %>
    </textarea> </br>
    <input type="submit" class="styled-button-2" value="Translate" name="query" /> </br>
    <textarea name="Output" id="styleid" text="" disabled>
    <%=
    request.getAttribute("Output")
    %>
    </textarea> 

以及标签的可见性JSP

     <label for="Syllabication" class="
     <%=request.getAttribute("Visibility")%>">Syllabication</label>

Servlet

    response.setContentType("text/html");
    request.setAttribute("Visbility","hidden");
    request.getRequestDispatcher("eng-chav.jsp").forward(request, response);

和隐藏类

    <style>
    .hidden{
       visibility:hidden;
    }
    </style>
<%
String msg=(String)request.getAttribute("Input");
if(msg==null)
{
    msg="";
}
%>

这不会输出任何内容,因为该值仅存储在msg中,不会在任何地方打印出来。你可能应该加上:

<%=
    msg
%>

在另一个文本区域中,您有:<%=request.getAttribute("输出")%>当您没有名为"Output"的属性时,它将打印出null。所以这可能就是你所看到的null的起源。

至于可见性问题,当你想让元素再次可见时,你只需要为这个案例添加另一个类。例如:

<style>
.hidden {
   visibility: hidden;
}
.visible {
   visibility: visible;
}
</style>

然后,您可以通过以下操作使servlet代码中的元素可见:

request.setAttribute("Visbility","hidden");