当前位置: 代码迷 >> Java Web开发 >> 【小问题求解】
  详细解决方案

【小问题求解】

热度:128   发布时间:2011-09-14 17:19:38.0
【小问题求解】
<table  align="center"width="392" height="230" border="0" cellpadding="0" cellspacing="0">
<form name="myform">
  <tr>
    <td bgcolor="#FF9999"><div align="center"><span class="STYLE2">送货地址确认</span></div></td>
  </tr>
  <tr>
    <td bgcolor="#FF9999" class="STYLE2"><div align="center">省份:
          <select name="select"id="select">
            <option>北京市</option>
            <option>山东省</option>
            <option>河北省</option>
          </select>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#FF9999" class="STYLE2"><div align="center">城市:
        <select name="select2" id="select2"size="1">
          <option>北京市</option>
          <option>济南市</option>
          <option>石家庄市</option>
        </select>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#FF9999" class="STYLE2"><div align="center">区:
        <select name="select3" id="select3"size="1">
          <option>西城区</option>
          <option>高新区</option>
          <option>历城区</option>
        </select>
    </div></td>
  </tr>
  </form>
</table>
写这么多其实很简单,就是想问一下怎样取出列表项中的值,这是弹出的一个页面,我想将列表子项值提取出来显示在主页面的文本框中,来点代码吧,好理解
搜索更多相关主题的帖子: div  河北省  北京市  山东省  

----------------解决方案--------------------------------------------------------
你这个是取不到值的,改option改一下
   <select name="select"id="select">
            <option value="北京市">北京市</option>
            <option value="山东省">山东省</option>
            <option value="河北省">河北省</option>
</select>
----------------解决方案--------------------------------------------------------
index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
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 'index.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>
    <%
        request.setCharacterEncoding("gbk");
        String s1 = request.getParameter("select1");
        String s2 = request.getParameter("select2");
        String s3 = request.getParameter("select3");
        out.println(s1+","+s2+","+s3);
     %>
  </body>
</html>



test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
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 'test.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>
  <form action="./index.jsp" method="post">
   <table  align="center"width="392" height="230" border="0" cellpadding="0" cellspacing="0">
   
      <tr>
    <td bgcolor="#FF9999"><div align="center"><span class="STYLE2">送货地址确认</span></div></td>
      </tr>
      <tr>
        <td bgcolor="#FF9999" class="STYLE2"><div align="center">省份:
          <select name="select1" id="select">
            <option>北京市</option>
            <option>山东省</option>
            <option>河北省</option>
          </select>
        </div></td>
      </tr>
      <tr>
    <td bgcolor="#FF9999" class="STYLE2"><div align="center">城市:
        <select name="select2" id="select2"size="1">
          <option>北京市</option>
          <option>济南市</option>
          <option>石家庄市</option>
        </select>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#FF9999" class="STYLE2"><div align="center">区:
        <select name="select3" id="select3"size="1">
          <option>西城区</option>
          <option>高新区</option>
          <option>历城区</option>
        </select>
    </div></td>
  </tr>


</table>
<div align="center"><input type="submit" value="确认"/></div>
  </form>
  </body>
</html>

效果展示:
test.jsp


index.jsp


界面我就没做了,我就按群主的意思显示在主页上,美观上不用纠结。。。

----------------解决方案--------------------------------------------------------
这是test界面。。上面那个是index界面

----------------解决方案--------------------------------------------------------
  相关解决方案