0

I am trying to display all results from a database but i get the following errors on the results loop: Cannot cast from Vector to Integer Cannot cast from Vector to String

<% 
    Vector<Object> Results = scoreBean.getAllResults();
    String homeTeam;
    String awayTeam;
    int homeScore;
    int awayScore;
    final int NUM_FIELDS = 4;



for (int i=0;i<Results.size()/NUM_FIELDS;i++) 
{
 homeTeam = (String)Results.elementAt(i*NUM_FIELDS); \\\error here
            awayTeam = (String)Results.elementAt(i*NUM_FIELDS + 1); \\\error here
            homeScore = (Integer)Results.elementAt(i*NUM_FIELDS + 2);\\\error here
            awayScore = (Integer)Results.elementAt(i*NUM_FIELDS + 3);\\\error here

    %>  
    <TR>
        <TD><%= homeTeam %></TD>
        <TD><%= awayTeam %></TD>
        <TD><%= homeScore %></TD>
        <TD><%= awayScore %></TD>
    </TR>
    <%
         } 

If you are using Apache with mod_wsgi then you can use mod_xsendfile

You are essentially looking to run the authorisation for some resources via Django, pass a header back to Apache saying 'Hey dude, lighten up. This user is okay to access this' Apache will then handle returning the resource.

Rough steps (as in, rough enough that you will need to do a little more research using the links I provide as a starting point)

Apache needs to know which resources are public and which aren't. Create a sub directory under media for both of these types (Why not go crazxy and call them /media/public/ and /media/private/)

Set up an alias for the public directory and a WSGIScriptAlias for the protected dir, the protected alias will be pointing to your main site handler (probably django.wsgi)

Add settings to vhost: XSendFile On XSendFileAllowAbove On

Add an urlconf to your Django app that handles /media/protected/{whatever} and routes it through your auth Django app auth logic. An example of this is here

A useful snippet for the above is here and another example for good measure here

4

1 回答 1

1

从错误中,很可能存储在中的值Vector实际上不是整数:

homeScore = (Integer)Results.elementAt(i*NUM_FIELDS + 2);\\\error here
awayScore = (Integer)Results.elementAt(i*NUM_FIELDS + 3);\\\error here

因此ClassCastException. 检查集合中存储的值的类型。

一些注意事项:

  • Vector收藏品已过时。改用一个ArrayList
  • 使用 scriptlet 也是一个坏主意,请考虑使用JSTL forEach来遍历集合。
于 2013-05-06T15:04:27.847 回答