返回信息流问题如下:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page session="true" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.IOException"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>the weather of different cities</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String name=(String)session.getAttribute("name");
String add=(String)session.getAttribute("add");
String ate=(String)session.getAttribute("ate");
String emp=(String)session.getAttribute("emp");
String urtem=(String)session.getAttribute("urtem");
String indsp=(String)session.getAttribute("indsp");
%>
<script language="javascript">
function yjchang(){
document.form1.submit();
}
// document.form1.getSelection();
</script>
<form action="GetWeatherServlet" method="post" name="form1">
<table width="432" border="0" cellpadding="0"><tr><td height="36" >cityname:</td>
<td>
<select name="namecity" id="namecity" onChange="yjchang()">
<%
ResultSet rs=null;
PreparedStatement ps=null;
String url="jdbc:mysql://localhost/wea?user=root&password=abc123&useUnicode=true";
Connection con;
Statement stmt;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
con=DriverManager.getConnection(url,"root","abc123");
con.setAutoCommit(false);
stmt=con.createStatement();
rs=stmt.executeQuery("select *from weatian");
while(rs.next())
{
%> <option value='<%=rs.getString("name")%>'><%=rs.getString("name")%></option>
<%
}
rs.close();
stmt.close();
con.close();
}
catch(java.lang.Exception e){
System.err.println(e.getMessage());
}
%>
</select>
</td></tr></table>
</form>
<table width="432" border="0" cellpadding="0" cellspacing="1" bgcolor="#d5e1ef">
<tr>
<td width="151" height="82"><%=name%></td>
<td class="wht3 lk2e"><img width="64" height="64" src=<%=add%>></td>
</tr>
<tr>
<td height="77">date:<%=ate%></td>
<td height="77">
<div>tem:<%=emp%></div>
<div>curtemp:<%=urtem%></div>
<div></div>windspd:<%=indsp%><br>
</body>
</html>
jsp下拉框里的数据是从数据库里得到的,提交给servlet后,servlet查询数据库,(jsp页面和servlet连接查询是同一张表)返回给jsp 显示在table里
问题是下拉框里面的值被选中一个后不能相应的在cityname 后的小框里显示出来,该怎么解决
本人刚学习做网页,望大牛指教
这是一条镜像帖。来源:北邮人论坛 / java / #14567同步于 2010/5/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
好崩溃呀 昨天被我删帖的问题 希望哪位好心的同学帮忙
molihua
2010/5/13镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
我本想这样解决的:
%> <option value='<%=rs.getString("name")%>'<%name=(String)session.getAttribute("name");if(name.trim().equals(rs.getString("name").trim()))
{out.println(" selected=true ");} %>><%=rs.getString("name")%>
<%
但是改过之后,数据库都连不上了
说了不让你在jsp写sql语句的吧
jsp页面的代码都删掉,在servlet里面写
具体做法:rs中的数据存放到list中去
然后再在jsp中取出来