问题描述
<select name="phototype"> <%List list=(List)request.getSession().getAttribute("album"); for(int i=0;i<list.size();i++){%> <option value="<%=list.get(i)%>"><%=list.get(i)%></option> <%} %> </select>是从数据库中取几个String,然后在页面得下拉框中显示,好长时间没用el表达式,有点忘记了!方法 public List<String> getAlbum(HttpServletRequest request,ActionForm form )throws Exception { con=MyJdbc.getConnection(); String getAlbumSql="select phototype from phototype"; PreparedStatement pst=con.prepareStatement(getAlbumSql); ToUploadPhotoForm toUploadPhotoForm = (ToUploadPhotoForm )form; ResultSet rs=pst.executeQuery(); List<String> list=new ArrayList<String>(); while(rs.next()){ list.add(rs.getString("phototype")); } return list; }actionpublic ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {System.out.println("in action"); PhotoLogic photoLogic=new PhotoLogic(); List<String> list= photoLogic.getAlbum(request, form); request.getSession().setAttribute("album", list); return mapping.findForward("toUploadPhoto");}我本来是放到request里的,在页面取不到,然后放到session中了!问题补充:el表达式解决了,问下问什么放到request中不行,而必须放到session中!我知道不应该放到session中,问题处在哪啊!
解决方案
el也能获取request的参数他是有优先级的,session比request优先级高你应该获取request参数,不应该用session为什么取不到你应该查一下文档
解决方案二:
action到配置文件struts-config.xml有问题,<forward name="" path" redirect="true"></forward>默认redirect是false,不要指定 redirect="true" 应该就可以了。
解决方案三:
用jstl标签把