我正在尝试使用spring框架在java中开发网络监控应用程序..它列出了网络中的所有资源。点击其中一个资源ID,页面必须重定向到新页面,显示该页面的所有详细信息resource..ie,下一页根据我们点击的资源ID改变新内容。 现在我只是通过映射控制器中的页面来连接下一页。但是页面是空的......我的值没有传递给控制器。请帮助我。 提前谢谢
在我的控制器页面中..
@RequestMapping(value =“/ deviceInformation”,method = RequestMethod.GET)
public String deviceinfo(ModelMap model,HttpServletRequest request){ List list = inventoryService.getNetworkInterfaces(“”); Listlist2 = inventoryService.getNetworkServices( “ipResource.discoveredName”); Listlist3 = inventoryService.getEquipments( “RESOURCEID”); Listlist4 = inventoryService.getProcessors( “HOSTID”); Listlist5 = inventoryService.getSoftwaresRunning( “HOSTID”); Listlist6 = inventoryService.getStorageDisks( “HOSTID”); Listlist7 = inventoryService.getStorageMemories( “HOSTID”);
model.addAttribute("INlist", list);
model.addAttribute("Serlist",list2);
model.addAttribute("Eqlist", list3);
model.addAttribute("Prolist",list4);
model.addAttribute("SRlist",list5);
model.addAttribute("Storlist",list6);
model.addAttribute("StoMry",list7);
return "inventory/deviceInformation";
}
随着你所说的改变, @RequestMapping(value =“/ interfaceList / {ipResource.discoveredName}”,method = RequestMethod.POST) public ModelAndView getInterface(@PathVariable String resourceId,HttpServletRequest request, HttpServletResponse响应){ System.out.println(“获得请求参数:”+ resourceId);
List<NetworkInterface> list=inventoryService.getNetworkInterfaces("resID");
List<NetworkService> list2=inventoryService.getNetworkServices("ipResource.discoveredName");
List<Equipment>list3=inventoryService.getEquipments("ipResource.discoveredName");
List<Processor>list4=inventoryService.getProcessors("hostId");
List<SoftwareRunning>list5=inventoryService.getSoftwaresRunning("hostId");
List<StorageDisk>list6=inventoryService.getStorageDisks("hostId");
List<StorageMemory>list7=inventoryService.getStorageMemories("hostId");
ModelAndView modelAndView = new ModelAndView("/inventory/deviceInformation");
modelAndView.addObject("INlist", list);
modelAndView.addObject("Serlist",list2);
modelAndView.addObject("Eqlist", list3);
modelAndView.addObject("Prolist",list4);
modelAndView.addObject("SRlist",list5);
modelAndView.addObject("Storlist",list6);
modelAndView.addObject("StoMry",list7);
return modelAndView;
}
答案 0 :(得分:1)
这是一个示例,它有一个spring控制器和两个jsp文件。此示例仅用于帮助目的,并不意味着使用spring MVC的最佳实践。 控制器:
@RequestMapping(value="/getdevices")
public ModelAndView generateTable(){
ModelAndView mv = new ModelAndView("table");
List<Device> devices = new ArrayList<Device>();
devices.add(new Device(1,"Iphone5",500.00));
devices.add(new Device(1,"Iphone4s",450.00));
mv.addObject("devices", devices);
return mv;
}
@RequestMapping(value="/getdeviceinfo")
public ModelAndView getDeviceInfo(@RequestParam Integer id, @RequestParam String name,@RequestParam Double price){
ModelAndView mv = new ModelAndView("device");
Device device = new Device(id,name,price);
mv.addObject("device", device);
return mv;
}
table.jsp(生成包含指向每个设备信息页面的链接的设备列表)
<ul>
<c:forEach var="device" items="${devices}">
<li><a href="getdeviceinfo?id=${device.id}&name=${device.name}&price=${device.price}">${device.name}</a></li>
</c:forEach>
</ul>
device.jsp(个别设备的信息)
<body>
${device.name}
</body>
device.java(simple pojo)
public Integer id;
private String name;
private Double price;
public Device(Integer id, String name, Double price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
注意:我注意到在您的最新代码中,您已将View设置为“/ inventory / deviceInformation”。我不确定你的网络应用程序结构是什么样的。 View的值取决于web根目录下结构化jsp文件的方式以及spring视图解析器的前缀。 例如,在我的测试spring web应用程序中,我在/ webapp / WEB-INF / views下面有table.jsp和device.jsp,而spring配置就像
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
如您所见,在上面的控制器中,视图中没有前导斜杠,例如新的ModelAndView(“table.jsp)