Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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-未获取requestScope列表<;字符串>;来自Servlet_Java_Html_Jsp - Fatal编程技术网

Java JSP-未获取requestScope列表<;字符串>;来自Servlet

Java JSP-未获取requestScope列表<;字符串>;来自Servlet,java,html,jsp,Java,Html,Jsp,我已经为此寻找了很多解决方案,但没有任何效果。 我有一个生成列表的Servlet,并将其发送到.jsp,但无法检索列表。我尝试设置为sessionScope和requestScope,但仍然不起作用。我从Servlet访问页面,在控制台(System.out.prinltn)上打印列表项,这些项就在那里 我的Servlet代码: @WebServlet(name = "ValidaLoginHotelServlet", urlPatterns = {"/ValidaLoginHotelServl

我已经为此寻找了很多解决方案,但没有任何效果。 我有一个生成列表的Servlet,并将其发送到.jsp,但无法检索列表。我尝试设置为sessionScope和requestScope,但仍然不起作用。我从Servlet访问页面,在控制台(System.out.prinltn)上打印列表项,这些项就在那里

我的Servlet代码:

@WebServlet(name = "ValidaLoginHotelServlet", urlPatterns = {"/ValidaLoginHotelServlet"})
public class ValidaLoginHotelServlet extends HttpServlet {
    @Resource(name="jdbc/SistemaHotelLocal")
    DataSource dataSource;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        LoginHotelFormBean lhfb = new LoginHotelFormBean();
        String comando = (String) request.getSession().getAttribute("comando");
        try {
            // Obs: BeanUtils é uma classe da biblioteca
            // Apache Commons BeanUtils
            // http://commons.apache.org/beanutils/
            BeanUtils.populate(lhfb, request.getParameterMap());
            HotelDAO hdao = new HotelDAO(dataSource);
            request.getSession().setAttribute("hotelLogado", lhfb);
            List<String> mensagens = lhfb.validar(hdao);    
            if (mensagens == null) {
                if(comando.equals("promocaoForm")){
                    SiteReservaDAO sdao = new SiteReservaDAO(dataSource);
                    List<SiteReserva> todosSites = sdao.listarTodosSiteReserva();
                    List<String> urls = new ArrayList<>();
                    for(int i=0; i<todosSites.size(); i++){
                        urls.add(todosSites.get(i).getUrl());
                        System.out.println(urls.get(i)+" "+todosSites.get(i).getUrl());
                    }
                    request.setAttribute("listaSites", todosSites);
                    request.setAttribute("listaUrls", urls);
                    comando = comando+".jsp";
                    request.getRequestDispatcher(comando).forward(request, response);
                }
                else if(comando.equals("listaPromocoesHotel")){
                    String enviar = "/EnviaCnpjServlet?comando="+comando;
                    request.getRequestDispatcher(enviar).forward(request,response);
                }
            } else {
                request.setAttribute("mensagens", mensagens);
                request.getRequestDispatcher("loginHotel.jsp").forward(request, response);
            }
        } catch (Exception e) {
            request.setAttribute("mensagem", e.getLocalizedMessage());
            request.getRequestDispatcher("erro.jsp").forward(request, response);
        }
    }
...
@WebServlet(name=“ValidaLoginHotelServlet”,urlPatterns={”/ValidaLoginHotelServlet})
公共类ValidaLoginHotelServlet扩展了HttpServlet{
@资源(name=“jdbc/sistemhotellocal”)
数据源数据源;
受保护的void processRequest(HttpServletRequest请求、HttpServletResponse响应)
抛出ServletException、IOException{
setCharacterEncoding(“UTF-8”);
LoginHotelFormBean lhfb=新LoginHotelFormBean();
字符串comando=(字符串)request.getSession().getAttribute(“comando”);
试一试{
//Obs:BeanUtilséuma classe da biblioteca
//阿帕奇公地小海狸
// http://commons.apache.org/beanutils/
填充(lhfb,request.getParameterMap());
HotelDAO hdao=新HotelDAO(数据源);
request.getSession().setAttribute(“hotelLogado”,lhfb);
列表mensagens=lhfb.validar(hdao);
if(mensagens==null){
if(comando.equals(“promocaform”)){
SiteReservaDAO sdao=新的SiteReservaDAO(数据源);
List-todosSites=sdao.listarTodosSiteReserva();
列表URL=新的ArrayList();

对于(inti=0;i您是否尝试过不使用${listauls}之类的“requestScope”?它应该双向工作,但我想知道输出是否不同?正如您建议的那样尝试,仍然是相同的resultAs@randal4说,
requestScope.
应该被删除,因为它不是必需的。如果您的应用程序不能按预期工作,请求属性
listaUrls
为null或空。因此您应该添加
System.out.println(request.getAttribute(“listaUrls”);
位于
processRequest()的最后一行,并找出原因。
...
<ul class="urls"> 
<c:forEach items="${requestScope.listaUrls}" var="url"> 
<c:out value="${url}"/> 
</c:forEach> 
</ul>

<c:if test="${empty requestScope.listaUrls}">
<p>LIST IS EMPTY</p>
</c:if>
...