我已经用java编写了代码。所有的东西都工作正常。我只想返回未返回正确网页的 modelandview 的值。它正在抛出空白页。我的控制器的代码是:
public class Part3 extends HttpServlet {
Num num = new Num();
String name[];
Record record = null;
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ModelAndView mv = new ModelAndView();
String number = request.getParameter("number");
num.setNumber((number));
Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4j"));
Session session = driver.session();
StatementResult result = session.run("MATCH (tom {name: '" + number + "'}) RETURN tom.name, tom.born, tom.roles;");
while (result.hasNext()) {
record = result.next();
}
session.close();
driver.close();
request.setAttribute("selectObject", record);
mv.setViewName("index");
return mv;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
handleRequest(request, response);
} catch (IOException ex) {
Logger.getLogger(Part3.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
我的 HTML 页面是 index.html,它的代码是:
<form action ="number" name ="number">
<b>Enter Song ID:</b>
<input type="text" name='number' required placeholder="Enter SongID"><br /><br /><br />
<input type="submit" value="Submit" class="btn btn-primary" style="background-color: orangered"/>
</form>
${selectObject}
</div>