Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在JSP中填充页面加载的下拉列表_Java_Jsp_Arraylist_Drop Down Menu - Fatal编程技术网

Java 在JSP中填充页面加载的下拉列表

Java 在JSP中填充页面加载的下拉列表,java,jsp,arraylist,drop-down-menu,Java,Jsp,Arraylist,Drop Down Menu,这是我想在下拉列表中填充的数组列表 ArrayList<FriendRequestBean> friendRequests = (ArrayList<FriendRequestBean>) session.getAttribute("friendRequests"); 您需要对数据的引用。当您返回视图(猜测您正在使用控制器)时,您应该将数据(friendRequests)添加到模型对象中,然后您可以在视图文件(.jsp)中访问它;您通常不希望JSP文件中包含Java

这是我想在下拉列表中填充的数组列表

  ArrayList<FriendRequestBean> friendRequests = (ArrayList<FriendRequestBean>) session.getAttribute("friendRequests");

您需要对数据的引用。当您返回视图(猜测您正在使用控制器)时,您应该将数据(friendRequests)添加到模型对象中,然后您可以在视图文件(.jsp)中访问它;您通常不希望JSP文件中包含Java代码

示例:控制器

@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseStatus(value=HttpStatus.OK)
public String home(Locale locale, Model model,HttpServletRequest request) {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate );
    return "home";
}
现在home是视图(home.jsp),所以我们在jsp文件中有了它

Welcome
it is now ${serverTime}.

将控制器/页面张贴在您获取会话内容的地方,以便我们能够更好地提供帮助。
@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseStatus(value=HttpStatus.OK)
public String home(Locale locale, Model model,HttpServletRequest request) {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate );
    return "home";
}
Welcome
it is now ${serverTime}.