<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'select.jsp' starting page</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>
    <script language="javascript" type="text/javascript">
    function ChangeItem()
    {
    var name=form.name.value;
    window.location.href="New.jsp?name="+name;
    }
    </script>
    <% String name="";
     if(request.getParameter("name")!=null)
     {
     name=request.getParameter("name");
     }
    %>
    <form name="form" method="post" action="">
    <tr>
    <td width="70" height="30">查询条件:</td>
    <td width="180"><div align="left">
    <select name="name" style="width:160;border:1px solid;" onChange="ChangeItem()">
    <option>请选择</option>
    <option value="1"<%if(name.equals("1")){%>selected<%} %>>按论文题目查询</option>
    <option value="2"<%if(name.equals("2")){%>selected<%} %>>按指导老师查询</option>
    <option value="3"<%if(name.equals("3")){%>selected<%} %>>按审核状态查询</option>
    <option value="4"<%if(name.equals("4")){%>selected<%} %>>按论题性质查询</option>
    </select>
    </div></td>
    </tr>
    <%if(name.equals("1")){%>
    <tr align="center">
    <td height="30">关键字</td>
    <td><input type="text" name="point"></td>
    </tr>
      <%}if(name.equals("2")){%>
    <tr align="center">
    <td height="30">关键字</td>
    <td><input type="text" name="point"></td>
    </tr>
        <%}if(name.equals("3")){%>
    <tr align="center">
    <td height="30">关键字</td>
    <td>
    <input type="radio" name="yi" value="radiobutton"/>已审核
<input type="radio" name="yi" value="radiobutton"/>未审核
    </td>
    </tr>
        <tr align="center">
<%}if(name.equals("4")){%>
    <td>
    <input type="radio" name="ni" value="radiobutton"/>一般课题
<input type="radio" name="ni" value="radiobutton"/>自主命题
    </td>
    </tr>
    <%}%>
    <tr>
    <td height="30" colspan="2" align="center">
    <input type="submit" name="Submit2" value="查询">
    <input type="submit" name="Submit2" value="重置">
    </td>
    </tr>
    </form>
  </body>
</html>
我想实现一个功能,当点击查询按钮时,根据不同的下拉列表,显示不同的网页,该怎么实现例如当下拉列表显示“按指导老师查询”时,链接到以下页面
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>以指导老师查询</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>
  <%!String trans(String t)
  {
  String result=null;
  byte temp[];
  try
  {
   temp=t.getBytes("iso-8859-1");
   result=new String(temp);
  }
  catch(Exception e)
  {
  }
  return result;
  } %>
  <body>
  
<%
Connection con;
Statement sql;
ResultSet rs;String t=request.getParameter("ti");try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (Exception e)
{
out.print(e);
}
try
{
String uri="jdbc:mysql://localhost/lunwen";
con=DriverManager.getConnection(uri,"root","789456");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM lunwentopic WHERE lunwentimu LIKE '%"+trans(t)+"%'");
out.print("<table align=center border=1>");
out.print("<tr>");
out.print("<th width=160>"+"论文题目"+"</td>");
out.print("<th width=80>"+"指导老师"+"</td>");
out.print("</tr>");
while(rs.next())
{
out.print("<tr>");
out.print("<td align=center width=160>"+rs.getString(4)+"</td>");
out.print("<td align=center width=80>"+rs.getString(7)+"</td>");
out.print("</tr>");
out.print("</table>");
}
con.close();
}
catch(SQLException el)
{
out.print(el);
}
%>
  </body>
</html>
求高手指导

解决方案 »

  1.   

    <!--以下内容我放在linkSelector.jsp中--><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    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>My JSP 'select.jsp' starting page</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>
       <script language="javascript" type="text/javascript">
       function ChangeItem()
       {
           var name=form.name.value;
           //这里要注意下
           window.location.href="linkSelector.jsp?name="+name;
       }
       
       function submitForm()
       {
           var name=form.name.value;
           if(name=="1"){
            window.location.href="1.jsp";
           }
           
           if(name=="2"){
            window.location.href="2.jsp";
           }
           
           if(name=="3"){
            window.location.href="3.jsp";
           }
           
           if(name=="4"){
            window.location.href="4.jsp";
           }
           
           
       }
    </script>
       <% String name="";
       if(request.getParameter("name")!=null)
       {
              name=request.getParameter("name");
       }
       %>
       <form name="form" method="post" onSubmit="return false;">
       <tr>
       <td width="70" height="30">查询条件:</td>
       <td width="180"><div align="left">
       <select name="name" style="width:160;border:1px solid;" onChange="ChangeItem()">
       <option>请选择</option>
       <option value="1"<%if(name.equals("1")){%>selected<%} %>>按论文题目查询</option>
       <option value="2"<%if(name.equals("2")){%>selected<%} %>>按指导老师查询</option>
       <option value="3"<%if(name.equals("3")){%>selected<%} %>>按审核状态查询</option>
       <option value="4"<%if(name.equals("4")){%>selected<%} %>>按论题性质查询</option>
       </select>
       </div></td>
       </tr>
       <%if(name.equals("1")){%>
       <tr align="center">
       <td height="30">关键字</td>
       <td><input type="text" name="point"></td>
       </tr>
       <%}if(name.equals("2")){%>
       <tr align="center">
       <td height="30">关键字</td>
       <td><input type="text" name="point"></td>
       </tr>
       <%}if(name.equals("3")){%>
       <tr align="center">
       <td height="30">关键字</td>
       <td>
       <input type="radio" name="yi" value="radiobutton"/>已审核
     <input type="radio" name="yi" value="radiobutton"/>未审核
       </td>
       </tr>
       <tr align="center">
    <%}if(name.equals("4")){%>
       <td>
       <input type="radio" name="ni" value="radiobutton"/>一般课题
     <input type="radio" name="ni" value="radiobutton"/>自主命题
       </td>
       </tr>
       <%}%>
       <tr>
       <td height="30" colspan="2" align="center">
       <input type="submit" name="Submit2" value="查询" onClick="submitForm()">
       <input type="reset" name="Submit2" value="重置">
       </td>
       </tr>
       </form>
       </body>
    </html>接下来就自己发挥吧