Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从jsp获取到servlet的值_Java_Html_Jsp_Servlets - Fatal编程技术网

Java 无法从jsp获取到servlet的值

Java 无法从jsp获取到servlet的值,java,html,jsp,servlets,Java,Html,Jsp,Servlets,如果在将内容导出到excel时运行jsp,则不会在下载的excel文件中获取值。它只是空的。 这是我试过的 如何将表值传递给servlet Excel.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import ="javax.swing.JOptionPane"%> <!DOC

如果在将内容导出到excel时运行jsp,则不会在下载的excel文件中获取值。它只是空的。 这是我试过的

如何将表值传递给servlet

Excel.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ page import ="javax.swing.JOptionPane"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Export to Excel - Demo</title>
</head>
<body>

    <table align="left" border="2">
        <thead>
            <tr bgcolor="lightgreen">
                <th>Sr. No.</th>
                <th>Text Data</th>
                <th>Number Data</th>
            </tr>
        </thead>
        <tbody>
            <%
                for (int i = 0; i < 10; i++) {
            %>
            <tr bgcolor="lightblue">
                <td align="center"><%=i + 1%></td>
                <td align="center">This is text data <%=i%></td>
                <td align="center"><%=i * i%></td>
            </tr>
            <%
                }
            %>
        </tbody>
    </table>

    <p>
    fsfndfkdsfdkfjsfksfskfsfskfsfksfskf
    dfkdjfkfksfkkkkkkkkkjjjjjjjjj
    </p>

    <a href="Sample?exportToExcel=YES">Export to Excel</a>

</body>
</html>
试试这个:

<%@ page language="java" contentType="application/vnd.ms-excel"
pageEncoding="ISO-8859-1"%>
 <%@ page import ="javax.swing.JOptionPane"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Export to Excel - Demo</title>
</head>
<body>

<table align="left" border="2">
    <thead>
        <tr bgcolor="lightgreen">
            <th>Sr. No.</th>
            <th>Text Data</th>
            <th>Number Data</th>
        </tr>
    </thead>
    <tbody>
        <%
            for (int i = 0; i < 10; i++) {
        %>
        <tr bgcolor="lightblue">
            <td align="center"><%=i + 1%></td>
            <td align="center">This is text data <%=i%></td>
            <td align="center"><%=i * i%></td>
        </tr>
        <%
            }
        %>
    </tbody>
</table>

<p>
fsfndfkdsfdkfjsfksfskfsfskfsfksfskf
dfkdjfkfksfkkkkkkkkkjjjjjjjjj
</p>

<a href="Sample?exportToExcel=YES">Export to Excel</a>

Add out.printlnexportToExcel;在servlet中,让我们知道打印的内容。@user3152748的可能重复项删除当前帖子,或者你不应该因为急于得到回复而发送垃圾邮件。它显示了一个弹出窗口,可以在线下载文件。我不需要那个。如果单击“导出到Excel”,它将打开弹出窗口。有什么帮助吗?只换了这行
<%@ page language="java" contentType="application/vnd.ms-excel"
pageEncoding="ISO-8859-1"%>
 <%@ page import ="javax.swing.JOptionPane"%>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Export to Excel - Demo</title>
</head>
<body>

<table align="left" border="2">
    <thead>
        <tr bgcolor="lightgreen">
            <th>Sr. No.</th>
            <th>Text Data</th>
            <th>Number Data</th>
        </tr>
    </thead>
    <tbody>
        <%
            for (int i = 0; i < 10; i++) {
        %>
        <tr bgcolor="lightblue">
            <td align="center"><%=i + 1%></td>
            <td align="center">This is text data <%=i%></td>
            <td align="center"><%=i * i%></td>
        </tr>
        <%
            }
        %>
    </tbody>
</table>

<p>
fsfndfkdsfdkfjsfksfskfsfskfsfksfskf
dfkdjfkfksfkkkkkkkkkjjjjjjjjj
</p>

<a href="Sample?exportToExcel=YES">Export to Excel</a>