0

我正在尝试将 String[] 从 java 类传递给 jsp 文件,我设法传递了一个简单的字符串,但我现在被困在这个字符串上几天了。有人可以帮助我吗,我希望答案更详细,因为我是新手。

Java类:

public class UserArray extends Applet {

public String  javaArray [] =
        { "array 1", "array 2" , "array 3" };

public String [] getJavaArray() {
    return javaArray;
}
}

JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags" %>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <jsp:useBean id ="array" class="eu.xyx.ztr.applet.UserArray"/>
</head>
<body>
   <h4>

  <jsp:getProperty name ="array" property="javaArray"/> 

 </h4>

</body>

到目前为止,我已经获得了 String[] 的地址。我只想获取 javaArray 的值,如果可以以如下形式获取它们:

<script>

    function addrow(tableID){


        var numeuser=document.numeuser;

        var nume=["adrian","cristi","levi",numeuser];
        var prenume=["ric","dre","asd"];
        var email=["rew@td","qq@eqwq","ee@ew"];
4

2 回答 2

0

您应该使用 google JSON 或 jackson JSON 之类的 javascript 库来查看这些链接

http://viralpatel.net/blogs/creating-parsing-json-data-with-java-servlet-struts-jsp-json/

于 2013-09-17T07:46:25.857 回答
0

小服务程序

   protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    ArrayList myArray = new ArrayList();  
    myArray.add("array 1");  
    myArray.add("array 2");  
    myArray.add("array 3");  
    request.setAttribute("myArray", myArray);  

    //then call jsp :   
    RequestDispatcher rd = request.getRequestDispatcher("mypage.jsp");  
    rd.forward(request, response);  

}

jsp

  <body>
      <c:forEach var="myarr" items="${myArray}">     
        <c:out value="${myarr}" />      
      </c:forEach>   
 </body>
于 2013-09-17T09:04:28.370 回答