【发布时间】:2014-03-21 10:00:34
【问题描述】:
我的 maven 项目中有两个名为 bulletedList.java 和 blist.jsp 的文件作为 Web 应用程序。
我的 .jsp 文件链接到 .java 文件。并且有一个按钮可以在我按下该按钮后立即生成数字,然后 .java 文件会生成 4 个随机数并将它们转换为字符串。然后到了我想在 jsp 文件中使用这些生成的值作为项目符号列表的阶段,但我无法做到这一点。
bulletedList.java(servlet)的代码是:
public BulletedList() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<title>My BulletedList Servlet!</title>");
String No1 = "" + ((int) (Math.random() * 50));
String No2 = "" + ((int) (Math.random() * 25));
String No3 = "" + ((int) (Math.random() * 75));
String No4 = "" + ((int) (Math.random() * 99));
response.getWriter().write(No1);
response.getWriter().write(No2);
response.getWriter().write(No3);
response.getWriter().write(No4);
response.sendRedirect("bList.jsp");
//out.println("<h1>" + request.getParameter("No1") + "</h1>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
现在我不知道我需要做什么才能在 jsp 文件中使用这些值并在浏览器中显示它们。
我试过这个:
request.getParameter(No1) 在 (LI) 标记之后,但它只是将纯 No1 显示为文本,而不是显示存储在其中的任何由 math.random() 生成的随机值。
【问题讨论】:
标签: jsp maven servlets web-applications jsp-tags