Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将变量值从servlet显示到jsp_Java_Jsp_Servlets - Fatal编程技术网

Java 如何将变量值从servlet显示到jsp

Java 如何将变量值从servlet显示到jsp,java,jsp,servlets,Java,Jsp,Servlets,这是我的设想。我有这个jsp表单: welcome.jsp <div class="ajax-wrap" style="display: block; height:100%;"> <p class="overlay_title"> <%-- <span><%=request.getAttribute("mes_add_pageTitle")%></span> --%> <% String u

这是我的设想。我有这个jsp表单:

welcome.jsp

 <div class="ajax-wrap" style="display: block; height:100%;">
    <p class="overlay_title">
    <%-- <span><%=request.getAttribute("mes_add_pageTitle")%></span> --%>
    <% String userlabel=(String)request.getAttribute("mes_add_pageTitle");%>
    </p>
 </div>

我的问题是为什么我在jsp中得到空值。它应该显示
用户名标签
,但不起作用。。我犯了什么错请帮忙。注意:
用户名标签
是一个标签,所以我不需要get或post。感谢JSP中的

,mes_add_pageTitle变量需要在sriptlet()标记之外声明

在分派使用时像

一样声明它

req.getRequestDispatcher("/welcome.jsp").forward(req, resp);
在使用jsp进行检索时

<%=request.getAttribute("mes_add_pageTitle")%>

index.jsp:

 <form action=Servlet1">
 <input type="submit" value="submit" name="submit1">
  </form>
welcome.jsp:

<% String userlabel=(String)request.getAttribute("mes_add_pageTitle"); %>

Value is: <%=userlabel%>

价值是:

希望这能帮助您…

我仍然得到空值。我仍然得到空值:-(变量存储在servlet中,我想在jspmy欢迎文件index.jspI中显示它们。但是我仍然得到空值。我的代码怎么了?index.jsp welcome.jsp这是我在web.xml中的欢迎文件,我将代码放在哪里。在
doGet
函数或
doGet
?我在这个受保护的voi中尝试过d processRequest(HttpServletRequest,HttpServletResponse)抛出ServletException,IOException{我可以查看您的整个jsp文件吗?我仍然得到空值。您可以发布您的servlet和jsp页面吗..在这里再次编码吗?您是否尝试打印它..尝试使用或打印
if(request.getParameter("submit1")!=null)
{
String UsernameLabel="passing value";
request.setAttribute("mes_add_pageTitle",UsernameLabel); //Setting UsernameLabel to mes_add_pageTitle

RequestDispatcher rd=request.getRequestDispatcher("/welcome.jsp");
rd.forward(request,response);  //forwarded to welcome.jsp
<% String userlabel=(String)request.getAttribute("mes_add_pageTitle"); %>

Value is: <%=userlabel%>