使用jsp的动态html表单

时间:2015-09-02 06:43:20

标签: html jsp

我想在jsp中用jsp中声明的String填充html表单的值部分。我正在使用jsp EL:

<% 
  ResultSet rs=statement.executeQuery("select id from mytable");   
  String id=rs.getString(1); 
%>
<form action="process.jsp" method="post">   
  ID: <input type="text" name="myId" value="${id}"> 
</form>

但它发出错误说:

  

输入标记位置无效

3 个答案:

答案 0 :(得分:0)

然后你应该放在你的下方:

String id=rs.getString(1); 

此代码:

pageContext.setAttribute("id", id);

答案 1 :(得分:0)

您只需将DECLARE @cols AS NVARCHAR(MAX) = '', @query AS NVARCHAR(MAX) SELECT @cols = COALESCE(@cols+', ','') + '[' + cast(product_ID as varchar) + ']' FROM product SET @query = N'SELECT * FROM ( SELECT year(createdDate) as [year],month(createdDate) as [month],cp.product_Id as product_ID,cp.salesprice as Amount FROM customer_products cp )s PIVOT ( SUM(Amount) FOR product_Id IN ( '+ @cols +' )) AS pvt;' EXECUTE(@query) 标记放在inputfieldset块中,因为严格div格式的输入必须包含在HTML

  

fieldset - HTML | MDN 文档中,它说:

     

HTML元素也用于对多个控件进行分组   作为网络表单中的标签()。

并确保关闭fieldset代码,您的代码应如下所示:

input

答案 2 :(得分:0)

请你试试这个没有这样的EL ..

<% 
ResultSet rs=statement.executeQuery("select id from mytable");   
String id=rs.getString(1); 
%> 
<form action="process.jsp" method="post">   
ID: <input type="text" name="myId" value="<%=id%>"> 
</form>