I'm trying to take input for a matrix , that is a multidimensional array from JSP page and print it. I tried what i can,
INDEX.JSP
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>TSP</title>
</head>
<body>
<h1> Matrix</h1>
<form action="tsp.jsp">
<label>No of cities</label>
<input type="text" name="cities">
<label>Enter matrix</label>
<input type="text" name="matrix">
<button type="submit">Submit</button>
</form>
</body>
</html>
TSP.JSP
<%--
Created by IntelliJ IDEA.
User: Abhishek
Date: 11/21/2018
Time: 12:01 PM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Display</title>
</head>
<body>
<% int city= Integer.parseInt(request.getParameter("cities"));
int matrix[][]=new int[100][100];
for ( int i=0; i<city;i++) {
for (int j = 0; j < city; j++) {
matrix[i][j]= Integer.parseInt(request.getParameter("matrix"));
}
}
%>
<% out.print(city);
for ( int i=0; i<city;i++) {
for (int j = 0; j < city; j++) {
out.print(matrix);
}
}
%>
</body>
</html>
When i enter the values city as 4 , matrix = 1 2 3 4 5 6 7 8 8 8 8 8 1 2 3 4 and click submit it shows the exception:
java.lang.NumberFormatException: For input string: "1 2 3 4 5 6 7 8 8 8 8 8 1 2 3 4"
The purpose for this is basically, if this becomes successful i want to pass these to java class to solve the Travelling Salesman Problem. The program is running fine. I wanted create a web interface for it and i'm stuck at this point.