JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 下拉式選單選取後reflash畫面
supper03





發文: 59
積分: 0
於 2011-12-01 11:10 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位好
請教一個問題,我想使用下拉式選單來撈取資料庫的值,這部分已經完成了,但撈出後卻reflash了畫面(有辦法不reflash嗎)變成錯誤如下圖,請問該怎麼辦呢
選單如下

隨機選擇後


提供程式碼~
此段是提供介面可選取
1
2
3
4
5
6
7
8
9
10
11
<tr bgcolor="#D1DAE9">
            <td width="15%" height="30"><div align="center"><%=request.getParameter("channel_type")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="src_id" type="text" size="14" value="<%=request.getParameter("src_id")%>"></div></td>
            <td width="15%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("src_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("channel_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="eng_name" type="text" size="14" value="<%=request.getParameter("eng_name")%>"></div></td>
            <td width="15%" height="30"><div align="center"><select name="role" id="role" onChange="MM_jumpMenu('parent',this,0)">
                                                                            <option  value="modifySrcResult.jsp?">----</option>
                                                                      <rt:roleTag2 /></select>
                                                               <input name="role_id" type="hidden" value="<%=(request.getParameter("role")==null?"":request.getParameter("role"))%>"></div></td>
          </tr>    

由taglib連結
taglib程式
1
2
3
4
5
6
7
8
9
10
  <tag>
    <name>roleTag2</name>
    <tag-class>tw.com.vibo.www.tag.roleTag</tag-class>
    <body-content>JSP</body-content>
        <attribute>
       <name>reflashname</name>
       <required>false</required>
       <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>

下拉式選單內容寫在java中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package tw.com.vibo.www.tag;
 
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
 
import tw.com.vibo.www.singleton.connectionDB;
 
public class roleTag extends BodyTagSupport {
 
  HttpServletRequest request ;
  protected String roleName = null;
  protected String reflashname;
 
  public void setPageContext(PageContext pageContext)
  {
    this.pageContext = pageContext   ;
    request     =(HttpServletRequest) pageContext.getRequest();
  }   
 
  public int doAfterBody(){
 
    Hashtable hashtable;
 
    try
        {
            Vector vt = this.getroleType();
            JspWriter out = this.getPreviousOut();
            Iterator iterator = vt.iterator();
 
            while (iterator.hasNext())
            {
                hashtable = (Hashtable) iterator.next();
                String role_id = hashtable.get("role_id").toString();
                //取得已選定的通路別並更新畫面
                out.println("<option value=\""+reflashname+"role_id="+role_id+"\""+ (request.getParameter("role_id")==null?"":(request.getParameter("role_id").equals(role_id)?"selected":""))+"> "+hashtable.get("role_name").toString()+" </option>");
            }
      out.println(" </select>");
      out.println(" ");
 
    } catch (IOException e) {
      e.printStackTrace();
    }
     return SKIP_BODY;
  }
 
  protected Vector getroleType(){
 
    Vector vector = new Vector();
    Connection connection = connectionDB.getInstance().getConnection();
    ResultSet  rs = null;
 
    //取得通路別的資料
    //String queryString = "SELECT channel_type, channel_desc  FROM src_tab where channel_type ="+request.getParameter("channel")+"  order by src_id";
    //String queryString = "SELECT channel_type, channel_desc  FROM src_tab where "+(request.getParameter("channel")==null?" 0=0 ":"channel_type ="+request.getParameter("channel"))+"  order by src_id";
    String queryString = "SELECT role_id, role_name  FROM bank_role ";
 
    try {
      PreparedStatement ps = connection.prepareStatement(queryString);
      rs = ps.executeQuery();
 
      while (rs.next())
      {
                Hashtable ht = new Hashtable();
                ht.put("role_id", rs.getObject("role_id")== null ?"": rs.getObject("role_id"));
                ht.put("role_name", rs.getObject("role_name")== null ?"": rs.getObject("role_name"));
                vector.add(ht);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally{
      try {
              rs.close();
              connection.close();
          } catch (SQLException e1) {
            e1.printStackTrace();
          }
    }
    return vector;
  }
 
  public String getreflashname() {
    return reflashname;
  }
 
  public void setreflashname(String i) {
    reflashname = i;
  }
 
}


reply to postreply to post
作者 Re:下拉式選單選取後reflash畫面 [Re:supper03]
supper03





發文: 59
積分: 0
於 2011-12-01 13:23 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問是否還有需要的資料,我都可以提供,再麻煩協助一下~

reply to postreply to post
作者 Re:下拉式選單選取後reflash畫面 [Re:supper03]
pclevin





發文: 114
積分: 0
於 2011-12-01 14:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HTTP 狀態碼。
1xx: 資訊
2xx: 成功
3xx: 重定向
4xx: 用戶端錯誤
5xx: 伺服器錯誤
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

如果是404那就是找不到你的網頁檔案。

還有你的set與get,
supper03 wrote:
public String getreflashname() {
return reflashname;
}
public void setreflashname(String i) {
reflashname = i;
}
}



應該是這樣吧
setReflashname()
getReflashname(String i)

還有我記得BodyTagSupport,適用於有主體的標籤。
你的<rt:roleTag2/>是沒有主體的,真的有撈到資料嗎?

這是我發現你的code,奇怪的地方,看看有沒有幫助
還有你看看你的console應該會有其它的錯誤訊息吧。


reply to postreply to post
我的網誌
http://pclevin.blogspot.com
作者 Re:下拉式選單選取後reflash畫面 [Re:pclevin]
supper03





發文: 59
積分: 0
於 2011-12-01 17:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
PCL大大你好
謝謝您回覆問題,我有修改一下程式,首先針對這個問題

應該是這樣吧
setReflashname()
getReflashname(String i)

程式在執行時這邊是沒有出現錯誤的,我有稍微修改一下,請看結果


下拉式選單再選擇後會reflash畫面,其他值就變成null了
程式碼如下
1
2
3
4
5
6
7
8
9
10
11
<tr bgcolor="#D1DAE9">
            <td width="15%" height="30"><div align="center"><%=request.getParameter("channel_type")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="src_id" type="text" size="14" value="<%=request.getParameter("src_id")%>"></div></td>
            <td width="15%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("src_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("channel_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="eng_name" type="text" size="14" value="<%=request.getParameter("eng_name")%>"></div></td>
            <td width="15%" height="30"><div align="center"><select name="role" id="role" onChange="MM_jumpMenu('parent',this,0)">
                                                                            <option  value="modifySrcResult.jsp?">----</option>
                                                                      <rt:roleTag2 reflashname='modifySrcResult.jsp?'/></select>
                                                               <input name="role_id" type="hidden" value="<%=(request.getParameter("role")==null?"":request.getParameter("role"))%>"></div></td>
          </tr>    


可以在選擇時不reflash畫面嗎,印象中可用JQuery,但不確定如何套用到這,是否有其他方式達成呢?


reply to postreply to post
作者 Re:下拉式選單選取後reflash畫面 [Re:supper03]
pclevin





發文: 114
積分: 0
於 2011-12-01 17:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
最好是我看你那幾行code,我就可以知道你錯在那呀!
你這是練習程式,還是公司專案。
如果可以要看你相關的檔案。
取值是null,一定是你在上一支的request,沒有送過來這支程式。

如果你不想要程式reflash畫面
,可以用jQuery.ajax();
如果不知道什麼用去google找有很多


reply to postreply to post
我的網誌
http://pclevin.blogspot.com
作者 Re:下拉式選單選取後reflash畫面 [Re:pclevin]
supper03





發文: 59
積分: 0
於 2011-12-03 21:38 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
您好
我說明一下我要的功能 在權限角色名稱的下拉式選單中選出一個角色(下拉式選單有連結資料庫,資料庫的內容已寫在roleTag.java檔中),目的是選擇後 按確認修改把整條line存入資料庫裡
那我jsp該怎麼寫這個下拉式選單?權限角色秀出來的要是英文名字,但我要存的是對應的id

原本是用文字方塊來寫,現在是想改成下拉選單所以才提出這個疑問~
modifySrcResult.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<%@ page contentType="text/html; charset=big5" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/mainTemp.dwt.jsp" codeOutsideHTMLIsLocked="true" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<!-- InstanceBeginEditable name="doctitle" -->
<title>區處別修改畫面</title>
<%@ taglib uri="/tags/securityTag" prefix="st" %>
<%@ taglib uri="/tags/printRemitTag" prefix="pr" %>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.style1 {  font-family: "新細明體";
  font-weight: bold;}
-->
</style>
<style type="text/css">
<!--
.style5 {font-size: 16px}
-->
</style>
<style type="text/css">
<!--
.style6 {font-size: 16px; font-family: "新細明體"; }
-->
</style>
<link href="../resources/css/main.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style7 {color: #FF0000}
.style8 {font-size: 18px}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
function messageWindow(title, msg)
{
  var width="300", height="125";
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  var msgWindow = window.open("","msgWindow", styleStr);
  var head = '<head><title>'+title+'</title></head>';
  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"  self.toolbar.visible="false";></form>';
  msgWindow.document.write(head + body);
 
}
function MM_popupMsg(msg) { //v1.0
  alert('已確認執行修改,請重新查詢');
}
</script>
 
<script language="JavaScript"  src="../overlib_mini.js"></script>
 
<!-- InstanceEndEditable -->
 
<link href="../resources/css/main.css" rel="stylesheet" type="text/css">
</head>
 
<body>
 
<div align="center">
  <table width="800" height="437" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <th height="50" align="left" valign="top" scope="col"><table width="100%" height="15"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th width="39%" scope="row"><img src="../resources/images/company_r1_c2_new.jpg" width="150" height="50"></th>
            <td width="44%" height="12" background="../resources/images/company_r1_c3.JPG"></td>
            <td width="6%" height="15" valign="bottom" background="../resources/images/company_r1_c3.JPG"><div align="center" class="style2">
              <div align="center"><a href="../index.jsp" class="style3">回首頁</a></div>
            </div></td>
            <td width="6%" height="15" valign="bottom" background="../resources/images/company_r1_c3.JPG"><div align="center" class="style2">
              <div align="center"><a href="javascript:history.go(-1)" class="style3">回上頁</a></div>
            </div></td>
            <td width="5%" valign="bottom" background="../resources/images/company_r1_c3.JPG"><div align="center"><span class="style2"><a href="../signOut" class="style3">登出</a></span></div></td>
            <td width="0%" height="15" valign="bottom" bgcolor="#FFFFFF"><div align="center" class="style2"></div></td>
          </tr>
        </table></th>
    </tr>
    <tr align="left" valign="top">
      <th width="790" height="363" scope="row"><!-- InstanceBeginEditable name="mainRegion" -->
    <table width="100%"  border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="100%" height="40" colspan="3" scope="col"><div align="center"><span class="subtitle">區處別修改</span></div></th>
        </tr>
    <tr>
            <td>
      <form name="form1" method="post" action="../modifySrc">
        <table width="100%" height="50" border="2" cellpadding="0" cellspacing="0">
                  <tr class="sidebarFooter">            
                      <td width="28%" height="50" class="sidebarFooter"><div align="center">通路別代碼</div></td>
                      <td width="14%" height="50" class="sidebarFooter"><div align="center">區處別代碼</div></td>
            <td width="14%" height="50" class="sidebarFooter"><div align="center">區處別名稱</div></td>
              <td width="14%" height="50" class="sidebarFooter"><div align="center">通路別名稱</div></td>
              <td width="15%" height="50" class="sidebarFooter"><div align="center">區處別別名</div></td>
              <td width="15%" height="50" class="sidebarFooter"><div align="center">權限角色名稱</div></td>                          
            </tr>
          <tr bgcolor="#D1DAE9">
            <td width="28%" height="30"><div align="center"><%=request.getParameter("channel_type")%></div></td>
            <td width="14%" height="30"><div align="center"><input name="src_id" type="text" size="14" value="<%=request.getParameter("src_id")%>"></div></td>
            <td width="14%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("src_desc")%></div></td>
            <td width="14%" height="30"><div align="center"><% request.setCharacterEncoding("big5"); %><%=request.getParameter("channel_desc")%></div></td>
            <td width="15%" height="30"><div align="center"><input name="eng_name" type="text" size="14" value="<%=request.getParameter("eng_name")%>"></div></td>
            <td width="15%" height="30"><div align="center"><input name="role_id" type="text" size="14" value="<%=request.getParameter("role_id")%>"></div></td>
          </tr>          
        </table>
        <tr><td><div align="right">
          <input type="submit" name="Submit1" value=" 確認修改 " onClick="MM_popupMsg()">
          <%
              session.setAttribute("channel_type",request.getParameter("channel_type"));
              session.setAttribute("src_id",request.getParameter("src_id"));
              session.setAttribute("src_desc",request.getParameter("src_desc"));
              session.setAttribute("channel_desc",request.getParameter("channel_desc"));
                            session.setAttribute("eng_name",request.getParameter("eng_name"));
                            session.setAttribute("role_id",request.getParameter("role_id"));
          %>
        </div></td></tr>
      </form>
      </td>
    </tr>                
      </table>
    <!-- InstanceEndEditable --></th>
    </tr>
    <tr>
      <th height="50" scope="row"><%@ include file="../right.htm" %></th>
    </tr>
  </table>
</div>
</body>
<!-- InstanceEnd --></html>  

如需要其他程式碼可提出~會盡量提供您足夠的資訊~


supper03 edited on 2011-12-03 21:46
reply to postreply to post
作者 Re:下拉式選單選取後reflash畫面 [Re:supper03]
pclevin





發文: 114
積分: 0
於 2011-12-05 09:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你可以用jQuery Ajax寫
http://api.jquery.com/category/ajax/


reply to postreply to post
我的網誌
http://pclevin.blogspot.com
作者 Re:下拉式選單選取後reflash畫面 [Re:supper03]
jk47





發文: 116
積分: 0
於 2011-12-05 11:39 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
基本上 在你要改成下拉是選單的部分
可以用
1.iframe最快(你改動程式碼最少 雖然我不推薦這方法就是了)
2.頁面初始化時 用AJAX給預設值
ONCHANG時 用AJAX給值

最後 根據目前你的寫法 會出錯應該是自訂義TAG的用法有問題 導致你下拉選單選擇時
頁面發動REQUEST 或是沒連到自訂義TAG

沒看到你這段完整的設定 無法判斷問題在哪

上述2個做法可以去膜拜孤狗大神看用法


reply to postreply to post
喝著濃濃的JAVA,看著MYSQL耀出水面
旁邊NetBeans抓著GlassFish與DUKE在嬉鬧
現在手上又拿著ORACLE在研究
(ORACLE=甲骨文=契文)
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8