问一个简单的问题。wap页面里面怎么样传多个参数?

troopers 2004-10-22 09:28:30
各位大哥大姐:
小弟刚接触wap开发。在这里问一个比较简单的问题。wap里面怎么样传递多个参数?

这是我写的javabean

package com.cellcom.wap;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.Date;
import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

public class allUserIt
{

private Connection con;
private Statement smt;
private Context _pool_ctx;
private Statement _pool_stmt;
private DataSource _pool_ds;

public allUserIt()
{
con = null;
smt = null;
}

public String IsoToGb(String s)
{
try
{
s = new String(s.getBytes("GB2312"), "ISO8859-1");
}
catch(Exception exception)
{
exception.printStackTrace();
}
return s;
}

public String GbToIso(String s)
{
try
{
s = new String(s.getBytes("ISO8859-1"), "GB2312");
}
catch(Exception exception)
{
exception.printStackTrace();
}
return s;
}

public String processString(String s)
throws UnsupportedEncodingException
{
if(s == null)
s = "";
byte abyte0[] = s.getBytes("ISO-8859-1");
String s1 = new String(abyte0);
return s1;
}

public Connection conDataBase()
{
try
{
_pool_ctx = new InitialContext();
System.out.println("*-----*-----*-----*-----*-----*-----*-----*");
System.out.println("--> 时间:" + (new Date()).toString());
if(_pool_ctx == null)
System.out.println("--> 没有匹配的环境");
else
System.out.println("--> 环境匹配成功");
_pool_ds = (DataSource)_pool_ctx.lookup("java:comp/env/jdbc/connectDBwap");
if(_pool_ds == null)
System.out.println("--> 没有匹配的数据库");
else
System.out.println("--> 匹配数据库成功");
con = _pool_ds.getConnection();
if(con == null)
System.out.println("--> 从连接池取连接失败");
else
System.out.println("--> 从连接池取连接成功");
}
catch(Exception exception)
{
System.out.println("--> allUserIt.java产生了错误:" + exception.getMessage());
}
return con;
}

public int getTitleNum(String s, Statement statement)
throws SQLException
{
ResultSet resultset = statement.executeQuery("SELECT COUNT('subID') as af FROM Title WHERE subID='" + s + "' AND isRe='0'");
int i = 0;
if(resultset != null && resultset.next())
i = resultset.getInt("af");
resultset.close();
return i;
}

public int getAllTitleNum(String s, Statement statement)
throws SQLException
{
ResultSet resultset = statement.executeQuery("SELECT COUNT('subID') as af FROM Title WHERE subID='" + s + "'");
int i = 0;
if(resultset != null && resultset.next())
i = resultset.getInt("af");
resultset.close();
return i;
}

public StringBuffer splitText(String s)
{
StringBuffer stringbuffer = new StringBuffer();
for(StringTokenizer stringtokenizer = new StringTokenizer(s, "\n"); stringtokenizer.hasMoreTokens(); stringbuffer.append(stringtokenizer.nextToken() + "<br>"));
return stringbuffer;
}

public StringBuffer mainBBS() throws SQLException
{ String mainBBSTitle="";
String mainBBSId="";
StringBuffer buffer=new StringBuffer();
Connection connection = conDataBase();
Statement statement = connection.createStatement();
ResultSet resultset = statement.executeQuery("select * from mainBBS");
while(resultset.next())
{
mainBBSTitle = resultset.getString("main_tilte");
mainBBSId = resultset.getString("mainID");

buffer.append("<a href='subBBS.jsp?Id="+mainBBSId+"'>"+mainBBSTitle+"</a><br/>");
//buffer.append(mainBBSTitle);
}

resultset.close();
statement.close();
if(!connection.isClosed())
connection.close();
return buffer;
}
public StringBuffer subBBS(String s1)
throws SQLException
{String mainID="";
String subID="";
String subName="";
StringBuffer subbuffer=new StringBuffer();
Connection subconnection = conDataBase();
Statement substatement=subconnection.createStatement();
ResultSet subresultset=substatement.executeQuery("select * from subBBS where mainID='"+s1+"'");
while(subresultset.next())
{mainID=subresultset.getString("mainID");
subID=subresultset.getString("subID");
subName=subresultset.getString("subName");
subbuffer.append("<a href='showsubtitle.jsp?mainID="+mainID+"&subID="+subID+"'>"+subName+"</a><br/>");
//subbuffer.append("<a href='showsubtitle.jsp?mainID="+mainID+"'>"+subName+"</a><br/>");
}
subresultset.close();
substatement.close();
if(!con.isClosed())
{con.close();
}
return subbuffer;
}
public void conClose()
throws SQLException
{
if(!con.isClosed())
con.close();
}
}
我在wml里面调用类里的subBBS方法的。我用jsp页面测试
<%@ page import="com.cellcom.wap.allUserIt"%>
<jsp:useBean id="getsubtitle" class="com.cellcom.wap.allUserIt" scope="request" />
<% out.print("<p>-----------</p>");
String Id="2";
StringBuffer subtitle=getsubtitle.subBBS(Id);
out.print("<p>"+subtitle.toString()+"</p>");
%>
可以得到正确的结果。

subBBS方法传出的结果为这样的形式

<a href='http://localhost:8080/wap/showsubtitle.jsp?mainID=2&subID=201'>"+"测试"+"</a>

传到wml里面的时候,两个参数之间用&符号连接就会提示
Fata Error.Ln 8,Col 70
Unterminated entity reference
URL:http://localhost:8080/wap/subBBS.jsp?Id=1的错误。
我将类改下。如果subBBS方法传出的结果为这样的形式的话

<a href='http://localhost:8080/wap/showsubtitle.jsp?mainID=2'>"+"测试"+"</a>
就不会出错。所以我认为打印出
<a href='http://localhost:8080/wap/showsubtitle.jsp?mainID=2&subID=201'>"+"测试"+"</a>时出了问题。
也就是传多个变量时候的问题。

请大家帮看看!


...全文
80 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
swsjk 2004-10-22
  • 打赏
  • 举报
回复
把&改成&

嘿嘿。。

790

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 其他移动相关
社区管理员
  • 移动开发其他问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧