Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Servlet/JSP/JSF/JavaFX Script
打印话题 寄给朋友 订阅主题 |
作者 | 求救!关于参数传递的问题。。。。。。。 |
snow_lxj
发贴: 7 |
于 2005-12-01 21:23
我在书上练习一个实例,代码如下:当categoryJSP.jsp中的newsCategory传递到titleJSP.jsp中时,输出乱码,不知道是怎么回事,还望各位大虾指点,小弟感激不尽,送上一百二十万分的感谢,!!! categoryJSP.jsp <%@ page contentType="text/html; charset=gb2312" %> <%@ page import="java.sql.*" %> <%@ page import="java.net.URL" %> <html> <head> <title> 新闻分类 </title> </head> <body> <center> <form action="titleJSP.jsp" method="post"> <% String url="jdbc:odbc:news"; String query="select distinct newsCategory from news"; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection(url); Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(query); out.println("<p>新闻种类如下:</p>"); out.println("<u1 type=\"square\">"); while(rs.next()){ String newsCategory=rs.getString("newsCategory"); out.println("<li>"); //写入超级链接"\"为转义符 out.println("<a href=\"titleJSP.jsp?newsCategory="+newsCategory+"\">"); out.println(newsCategory); out.println("</a>"); out.println("</li>"); } out.println("</ul>"); }catch(Exception e){ out.println(e.getMessage()); e.printStackTrace(); } %> </form> </center> </body> </html> titleJSP.jsp <%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.sql.*" %> <html> <head> <title>新闻标题:</title> </head> <body> <center> <% request.setCharacterEncoding("gb2312"); String newsCategory=request.getParameter("newsCategory"); out.print(newsCategory); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection("jdbc:odbc:news"); Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("select newsTitle from news"); out.println("<p>新闻标题如下:</p>"); out.println("<ul type=\"square\">"); while(rs.next()){ //取得新闻的标题名称 String newsTitle=rs.getString("newsTitle"); out.println("<li>"); //写入超级链接 out.println("<a href=\"newsJSP.jsp?newsTitle="+newsTitle+"\">"); out.println(newsTitle); out.println("</a>"); out.println("</li>"); } out.println("</ul>"); out.println(newsCategory); }catch(Exception e){ out.println(e.getMessage()); e.printStackTrace(); } %> </center> </body> </html> newsJSP.jsp <%@ page contentType="text/html;charset=gb2312" %> <%@ page import="java.sql.*" %> <html> <head> <title>课件内容</title> </head> <body> <center> <% String url="jdbc:odbc:news"; //request.setCharacterEncoding("gb2312"); String newsTitle=request.getParameter("newsTitle"); out.print(newsTitle); out.print("hello"); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=DriverManager.getConnection(url); Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("select newsContent from news where newsTitle="+"'"+newsTitle+"'"); while(rs.next()){ String newsContent=rs.getString("newsContent"); out.println("<p>"+newsTitle+"</p>"); out.println("<br>"); out.println("<p>"+newsContent+"</p>"); } }catch(Exception e){ out.print(e.getMessage()); e.printStackTrace(); } %> </center> </body> </html>
snow_lxj edited on 2005-12-01 21:33
Windows环境下的tomcat + apache配置(绝对实践操作版) |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
2305 | 求救!关于参数传递的问题。。。。。。。 | snow_lxj | 3525 | 2005-12-01 21:23 |
1739 | Re:求救!关于参数传递的问题。。。。。。。 | ntshenwh | 332 | 2005-12-04 17:07 |
1925 | Re:求救!关于参数传递的问题。。。。。。。 | snow_lxj | 10 | 2005-12-05 19:41 |
1926 | Re:求救!关于参数传递的问题。。。。。。。 | snow_lxj | 1236 | 2005-12-05 20:30 |
1879 | Re:求救!关于参数传递的问题。。。。。。。 | ntshenwh | 1410 | 2005-12-06 08:20 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |