java吧 关注:1,237,462贴子:12,709,420
  • 15回复贴,共1

大神求助,java后台向前台传值,不显示的问题

只看楼主收藏回复

try {
//TODO 取得所有字段
String sql = "Select MAIN_SERVER1 FROM MAPS_CMS_DB_CONN where MAPS_UID='"
+ maps_uid + "' AND MAPS_PASS = '" + passWord + "'";
String xml;
xml = webservers.selDepartmentMessage(sql, cmsid,
serverAddress);
branchreturnList = (ArrayList<Map<String, Object>>) xmltolist
.xml2List(xml);
if (branchreturnList.isEmpty()) {
response.getWriter().print("2");
} else {
String syncSever1 = (String) branchreturnList.get(0)
.get("MAIN_SERVER1");
request.setAttribute("serverAddress",syncSever1);
response.getWriter().print("1");
}
} catch (Exception e) {
e.printStackTrace();
}
//返回前台
request.getRequestDispatcher("index.jsp").forward(request,response);


IP属地:辽宁1楼2016-09-05 19:20回复
    前台代码:
    <tr style="height:30px">
    <td>远程服务器地址</td>
    <td colspan="3"><input id="serverAddress"
    name="serverAddress" type="text" style="width:100%"
    value=<%=serverAddress%>></input></td>
    </tr>


    IP属地:辽宁2楼2016-09-05 19:25
    回复
      session用过了,不好用。


      IP属地:辽宁3楼2016-09-05 19:26
      回复
        有大神吗?


        IP属地:辽宁4楼2016-09-05 19:34
        回复
          value="<%request.getAttribute("serverAddress")%>"


          来自Android客户端5楼2016-09-05 19:38
          收起回复
            你后台是request.setAttribute("serverAddress",syncSever1); 哪你前台就应该是request.getAttribute("serverAddress");啊


            IP属地:广东6楼2016-09-05 19:59
            收起回复
              你要先确定你if执行的是上面的代码块 还是一下面的代码块 如果是下面的 你要确定你的 syncSever1 有值


              IP属地:广东7楼2016-09-05 20:05
              收起回复
                置顶


                IP属地:辽宁8楼2016-09-05 20:32
                回复
                  /**
                  连接测试
                  **/
                  function serverTest() {
                  var maps_uid = document.getElementById("maps_uid").value;
                  var passWord = document.getElementById("passWord").value;
                  var url = "./saveServer?btnFlag=1&maps_uid="+maps_uid+"&passWord="+passWord;
                  //创建一个XMLHttpRequest对象req 请求后台
                  if (window.XMLHttpRequest) {
                  req = new XMLHttpRequest();
                  } else if (window.ActiveXObject) {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  req.open("POST", url, true);
                  req.onreadystatechange = calltest;
                  req.send();
                  }
                  前台调用后台方法。


                  IP属地:辽宁9楼2016-09-05 20:59
                  回复