我的RSS输入源地址为:http:wwww.xxxx.com/rss.jsp?id=xxx
遇见的问题: nbsp;未实例化 (对于特殊字符,我在类里用替换法,解决了)
输出全是乱码.但查源代码时,是正常的 之前输出格式是RSS,但今天输出却是乱码. 想看看各位大虾的例子.对RSS还不熟悉.
JSP代码如下: <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" >
<channel>
<jsp:directive.page import="java.util.Date"/>
<jsp:directive.page import="cn.xxx.inc.*"/>
<jsp:directive.page import="java.sql.*"/>
<jsp:directive.page import="cn.xxx.puser.logic.AllUse"/>
<jsp:directive.page import="cn.xxx.inc.Xml"/>
<%
request.setCharacterEncoding("utf-8");
int id=0 ;
String note_title="",note_content="",note_author="";
if (request.getParameter("id") !=null){
try{
id=Integer.parseInt(request.getParameter("id").toString());
}catch(Exception e)
{
id=0 ;
}
}
DB db=new DB();
AllUse allUse=new AllUse();
ResultSet rs=null;
String sql="select top 25 * from note order by note_addTime desc";
//System.out.println(sql);
try{
rs=db.Select(sql);
}catch(Exception e){
e.printStackTrace();
}
if(rs.next()){
note_author =allUse.getUserInfoField(id,"realname");
%>
<title>xiaochun的日记--</title>
<link>http://www.xxxxx.com </link>
<description>xxxxx网</description>
<language>zh-cn</language>
<image>
<title>xxxxx网</title>
<url>http://www.xxxxx.com/image/logo_1.jpg</url>
<link>http://www.xxxxx.com/</link>
</image>
<%
String dateStr="";
int noteId=0;
while(rs.next()){
dateStr=ConfigData.formatTime(rs.getString("note_addTime"),1);
noteId=rs.getInt("id");
note_title = new String(rs.getString("title").getBytes("utf-8"),"ISO-8859-1");
note_content = new String(ConfigData.getStrLen(rs.getString("content"),160).getBytes("utf-8"),"ISO-8859-1");
note_content=Xml.rss(note_content);
%>
<item>
<title><%=note_title %></title>
<link>http://localhost:8081/puser/diary.do?ac=det_ja&id=<%=noteId%></link>
<description><%=note_content%></description>
<pubDate><%=dateStr%></pubDate>
<guid>http://localhost:8081/puser/diary.do?ac=det_jaf&id=<%=noteId%></guid>
</item>
<%} //while end
}
else{ %>
<item>
<title>用户ID错误</title>
<link>http://www.xxxxx.com/</link>
<description>你输入的用户名ID错误,请确认你的ID http://www.xxxxx.com</description>
<pubDate>Sun, 29 Sep 2002 19:59:01 GMT</pubDate>
</item>
<%} %>
</channel>
</rss>
遇见的问题: nbsp;未实例化 (对于特殊字符,我在类里用替换法,解决了)
输出全是乱码.但查源代码时,是正常的 之前输出格式是RSS,但今天输出却是乱码. 想看看各位大虾的例子.对RSS还不熟悉.
JSP代码如下: <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" >
<channel>
<jsp:directive.page import="java.util.Date"/>
<jsp:directive.page import="cn.xxx.inc.*"/>
<jsp:directive.page import="java.sql.*"/>
<jsp:directive.page import="cn.xxx.puser.logic.AllUse"/>
<jsp:directive.page import="cn.xxx.inc.Xml"/>
<%
request.setCharacterEncoding("utf-8");
int id=0 ;
String note_title="",note_content="",note_author="";
if (request.getParameter("id") !=null){
try{
id=Integer.parseInt(request.getParameter("id").toString());
}catch(Exception e)
{
id=0 ;
}
}
DB db=new DB();
AllUse allUse=new AllUse();
ResultSet rs=null;
String sql="select top 25 * from note order by note_addTime desc";
//System.out.println(sql);
try{
rs=db.Select(sql);
}catch(Exception e){
e.printStackTrace();
}
if(rs.next()){
note_author =allUse.getUserInfoField(id,"realname");
%>
<title>xiaochun的日记--</title>
<link>http://www.xxxxx.com </link>
<description>xxxxx网</description>
<language>zh-cn</language>
<image>
<title>xxxxx网</title>
<url>http://www.xxxxx.com/image/logo_1.jpg</url>
<link>http://www.xxxxx.com/</link>
</image>
<%
String dateStr="";
int noteId=0;
while(rs.next()){
dateStr=ConfigData.formatTime(rs.getString("note_addTime"),1);
noteId=rs.getInt("id");
note_title = new String(rs.getString("title").getBytes("utf-8"),"ISO-8859-1");
note_content = new String(ConfigData.getStrLen(rs.getString("content"),160).getBytes("utf-8"),"ISO-8859-1");
note_content=Xml.rss(note_content);
%>
<item>
<title><%=note_title %></title>
<link>http://localhost:8081/puser/diary.do?ac=det_ja&id=<%=noteId%></link>
<description><%=note_content%></description>
<pubDate><%=dateStr%></pubDate>
<guid>http://localhost:8081/puser/diary.do?ac=det_jaf&id=<%=noteId%></guid>
</item>
<%} //while end
}
else{ %>
<item>
<title>用户ID错误</title>
<link>http://www.xxxxx.com/</link>
<description>你输入的用户名ID错误,请确认你的ID http://www.xxxxx.com</description>
<pubDate>Sun, 29 Sep 2002 19:59:01 GMT</pubDate>
</item>
<%} %>
</channel>
</rss>
加上: <%@ page contentType="text/html;charset=UTF-8" %> 试试