English 中文(简体)
jsp 页面中的动态内容表格
原标题:dynamic content table in jsp page
  • 时间:2012-05-26 10:53:57
  •  标签:
  • jsp

I have a problem with a jsp page (I m a novice). In a jsp page, I wrote a table that is read from a database. I write here the code of the page:

<%@page import="java.sql.SQLException"%>
<%@page import="java.lang.String"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.util.Date "%>
<%@page import="jord.ConnectionManager "%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% 
    String sql= "select numelencotrasm,dtelencotrasm 
"+
                "from fimand 
"+
                "where eser=2012 
"+
                "group by numelencotrasm,dtelencotrasm 
"+
                "order by numelencotrasm";
    ConnectionManager manager = new ConnectionManager();
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try{
        conn = manager.getConnection();
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
    }catch(SQLException ex){
        rs.close();
        conn.close();
        rs=null;
        conn=null;
        response.sendRedirect("../index.jsp");
    }
%>
<form id="tabella1" name="tabella1">
    <input name="numelencotrasm" type="hidden" value=""/>
    <input name="dtelencotrasm" type="hidden" value=""/>
    <table width="275px" cellspacing="0" cellpadding="1" border="1">
        <tr>
            <td class="TabellaTitolo" width="50%">
                Numero Distinta
            </td>
            <td class="TabellaTitolo" width="50%">
                Data Distinta
            </td>
            <td class="TabellaTitolo" width="50%">
                #
            </td>
        </tr>
        <%
        try{
            while(rs.next()){
        %>
        <tr>
            <td>
                <input type="text" value="<% out.print(rs.getInt(1)); %>"/>
            </td>
            <td>
                <input type="text" value="<% out.print(rs.getDate(2)); %>"/>
            </td>
            <td>
                <a href="#" onclick="javascript:setValue( <% out.print(rs.getInt(1)); %> , <% out.print(rs.getDate(2));%> );">
                    Click-me
                </a>
            </td>
        </tr>
        <%
            }
        }catch(Exception e){
            response.sendRedirect("../index.jsp");
        }
        %>
    </table>
</form>
<script language="Javascript">


    function setValue(num, dt){
        document.tabella1.numelencotrasm.value=num;
        document.tabella1.dtelencotrasm.value=dt;
        alert(document.tabella1.numelencotrasm.value); //test
        alert(document.tabella1.dtelencotrasm.value);//test
    }
</script>

。 现在我想在“ # ” 线上创建一个新的 html-able 点击, 从数据库中读取数据, 传递选定行的值 。

我为基本的英语道歉!

最佳回答

您需要对上述jsp 代码进行以下修改:

  1. Add action URL to your form.
  2. Make a call to submit form, after call to setValue().

在行动jsp中:

  1. Capture the parameters submitted by the above page,
  2. Process on them further for detailed data from your database,
  3. Construct an html table, and fill it to display.

这是一个简单的解决方案, 认为你刚刚开始学习。

<强 > 更新1 :

我想在单击表1时显示一个包含日期表2 的iframe。

为此,您需要修改您当前 JSP 的修改 。

  1. Define action URL as another JSP. It shall be something like action="targetPage.jsp".
  2. Define target attribute value for the form as your iframe. It shall be like target="nameOfTheIframe".
  3. Define and place an iframe in the page as appropriately. It shall be similar to <iframe name="targetIframe" src="about:blank"></iframe>.
  4. In the JavaScript setValue function write instructions to submit the form.
  5. In your other JSP, receive parameters submitted by this form, process them and display result.
问题回答

暂无回答




相关问题
Convert typed-in Text to lowercase

I ve got an index.jsp with [snip] <% String name = request.getParameter("name"); String pass = request.getParameter("pass"); String globalname = "webeng"; String globalpass = "2009"; ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Evaluate dynamically constructed JSP at runtime

I have a requirement where in the JSP page itself is created by the user and stored in the database. When viewing results we need to render this JSP to the client, evaluating all tags inside this JSP. ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

ArrayList to Table in JSP

I have an ArrayList and i am trying to display it in a table ..... ArrayList rows = .... ..... <table cellspacing="1" cellpadding="4" border="3"> <tr> <TH>...

热门标签