我曾尝试搜索相同的问题,但没有给出我需要的结果。我的 .jsp 文件中有一个输入框,需要从用户那里获取数组数据。用户按下Result按钮后,用户输入的数组数据仍然存储在输入框中。所以我有这段代码:
<%@ page import="RunPKmodelVII.Function"%>
<%@ page import="com.mathworks.toolbox.javabuilder.MWException"%>
<%@ taglib prefix="wf" uri="http://www.mathworks.com/builderja/webfigures.tld"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My Second Project</title> <
<link rel="Stylesheet" type="text/css" media=all href="./StyleSheet.css" />
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<%
String tf_simStr = request.getParameter("tf_sim");
int tf_sim = 10;
if (tf_simStr != null && tf_simStr.length() > 0) {
tf_sim = Integer.parseInt(tf_simStr);
}
String y0Str = request.getParameter("y0");
String y0 = "1 0 0 0";
if (y0Str != null && y0Str.length() > 0) {
y0 = Arrays.toString(y0Str);
}
%>
</head>
<body>
<center>
<h1>Development of Java Interface</h1>
<!--
<form action="http://localhost:8080/SecondServlet">
-->
<form action="SecondServlet">
<b>PK Model Calculation<br> <br></b>
<table align="center" border="1" bgcolor="#F5DEDE">
<thead>
<tbody>
<tr align="center">
<td>Time<br> <input type="text" name="tf_sim"
id="tf_sim" value="<%=tf_sim%>" /></td>
</tr>
<tr align="center">
<td>Initial Condition<br> <input type="text" name="y0"
id="y0" value="<%=y0%>" /></td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="10"> </td>
</tr>
<tr>
<td align="center" colspan="10"><input type="submit"
value="Result" name="DoPLot" id="DoPLot" /></td>
</tr>
</tbody>
</table>
<br> <br>
<div>
<wf:web-figure root="WebFigures" name="Project_Figure"
scope="session" />
</div>
</form>
</center>
</body>
</html>
问题是,只有第一个 View 会给出值“1 0 0 0”。用户更改此值(例如 2 1 0 1)后,输入框中的数字将变为“空”。我真的希望有人能提供帮助。提前致谢!
更新:我放了更多相关的代码供大家引用。如果您可以看到,第一个字符串 (tf_sim) 在按下结果按钮后将用户输入值存储在输入文本框中没有任何问题。但是无法根据需要存储第二个字符串 (y0) 的值。希望你能帮忙。谢谢!
最佳答案
我相信您正在访问一个字符串,就好像它是一个数组一样。试试这个:
if (y0Str != null && y0Str.length() > 0) {
y0 = y0Str;
}
关于javascript - 在html输入文本框中存储字符串数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25030863/