如何从一个jsp页面获取选项标签名称以选择另一个jsp页面的标签

时间:2015-09-28 09:44:07

标签: javascript jquery html jsp jasper-reports

Purchase.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>
<form method="post" action="view.jsp">
<select name="category">
<option name=''> Make a selection </option>
<option name='company'>company</option>
<option name='institution'>institution</option>
<option name='hospital'>hospital</option>
<option name='Others'>Others</option>
</select>


<input type='submit' value="Submit" />
</form>
</body>
</html>

view.jsp的

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
<script type="text/javascript">

    function setAction(nPage){
        document.forms[0].action = nPage;
    }

</script>
</head>
<body>
<form>
<% String Name=request.getParameter("category"); %>
<select  name="Name" onchange="setAction(this.value)">
<option value=''> Make a selection </option>
<option name="cat" value='PDF2.jsp'> PDF</option>
<option name="cat" value='XLS2.jsp'> XLS </option>
<option value='DOC.jsp'> DOC </option>
<option value='XLSX2.jsp'> XLSX </option>
</select>
&nbsp;&nbsp

<input type='submit' value="Submit">
</form>
</body>
</html>

现在我的问题是我需要得到&#34;公司&#34;从purchase.jsp到view.jsp的String Name并获取&#34; Name&#34;进入<select name="Name" onchange="setAction(this.value)">以便当我选择&#34; PDF.jsp&#34;然后点击提交,pdf仅包含&#34;公司&#34;的数据。没有别的。我在使用jasper报告将数据输入pdf。

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

<% String Name=request.getParameter("category"); %>
<select  name="<%=Name%>" onchange="setAction(this.value)">
<option value=''> Make a selection </option>
<option name="cat" value='PDF2.jsp'> PDF</option>
<option name="cat" value='XLS2.jsp'> XLS </option>
<option value='DOC.jsp'> DOC </option>
<option value='XLSX2.jsp'> XLSX </option>
</select>