1
我正在为使用JSP的Google应用程序引擎进行开发。我需要通过String类中的startsWith()方法比较两个字符串。比较两个字符串与开始时的汇编错误
这是我正在处理的代码。
<%
String artist = "Surendra Perera";
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key songKey = KeyFactory.createKey("songs", 123454);
// Run an ancestor query to ensure we see the most up-to-date
// view of the songs.
Query query = new Query("Song", songKey).addSort("Artist");
//query.addFilter("Artist", Query.FilterOperator.IN, "Milton Mallawarachchi");
List<Entity> songsList = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(30));
if(songsList.isEmpty()){
%>
<p>There are no songs</p>
<%
}else{
%>
<ul class="playlist">
<%
for(Entity song : songsList){
if(artist.startsWith(song.getProperty("Artist"))){
%>
<li><a href="<%= song.getProperty("Link") %>"><%= song.getProperty("Title") %>  <span class="comment"><%= song.getProperty("Artist") %></span></a></li>
<% }}} %>
而且这里是我得到的错误....
HTTP ERROR 500
Problem accessing /search.jsp. Reason:
Unable to compile class for JSP:
An error occurred at line: -1 in the generated java file
[javac] C:\DOCUME~1\SILICO~1\LOCALS~1\Temp\Jetty_127_0_0_1_8888_war____.g0qk00\jsp\org\apache\jsp\search_jsp.java:178: cannot find symbol
[javac] symbol : method startsWith(java.lang.Object)
[javac] location: class java.lang.String
[javac] if(artist.startsWith(song.getProperty("Artist"))){
[javac] ^
[javac] 1 error
Stacktrace:
Caused by:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: -1 in the generated java file
[javac] C:\DOCUME~1\SILICO~1\LOCALS~1\Temp\Jetty_127_0_0_1_8888_war____.g0qk00\jsp\org\apache\jsp\search_jsp.java:178: cannot find symbol
[javac] symbol : method startsWith(java.lang.Object)
[javac] location: class java.lang.String
[javac] if(artist.startsWith(song.getProperty("Artist"))){
[javac] ^
[javac] 1 error
提前感谢!
谢谢!我将对象转换为字符串。由于我无法更改这些方法,因为它们是谷歌应用程序引擎API方法。但你的回答确实帮助我弄清楚了这个问题。 – Isuru
不客气。 – BalusC