0

I have tried to search for the same problems but those do not give the result that I need. I have an input box in my .jsp file, which need to get an array data from the user. After the user push the Result button, the array data given by the user is still stored in the input box. So I have this code:

<%@ 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">&nbsp;</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>

The problem is, only the 1st view will give the value '1 0 0 0'. After the user change this value (eg. 2 1 0 1), the numbers in the input box will change to 'null'. I really hope someone could help. Thanks in advance!

UPDATE: I have put in more related codes for everybody's reference. If you can see, the first string (tf_sim) does not have any problem with storing the user input value in the input text box after pushing the Result button. But the value for the second string (y0) could not be stored as needed. Hope you may help. Thanks!

4
  • Give us more code please. Do you have a form, where is the submit-button .... Commented Jul 30, 2014 at 7:25
  • Hi @PeterRader. Thanks for your time. I have updated the code for your reference. And the submit button is also inside the code too. Hope you may help. Thanks! Commented Jul 30, 2014 at 17:02
  • Are you expecting an array from y0? Commented Jul 30, 2014 at 17:03
  • Hi @JonathanCrowe. Yes. I am expecting an array from the user input value. Example, the initial value is "1 0 0 0" and if the user put in "2 0 0 1", this number is stored as "2 0 0 1" even they have pushed the Result button. Commented Jul 30, 2014 at 17:05

1 Answer 1

1

I believe you are accessing a string as if it was an array. Try this:

if (y0Str != null && y0Str.length() > 0) {
    y0 = y0Str;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Gosh!! Silly me..I forgot to try this under the type String..And it works really well..Thanks for your help! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.