954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to pass variable from Mysql to Jsp

Hi all. I'm new with jsp and i'm just looking for create a login solution.
I use a mysql database and what i'm looking for is what follows:

Make a query to my sql database and then insert the output of one field in a variable.
I need this variable to pass the "id" to a form ... maybe with this code i will explain better.

/* part of the page with sql query

<sql:setDataSource
	url="jdbc:mysql://localhost/table"
	driver="com.mysql.jdbc.Driver"
	user="user"
	password="password" />
	
	<sql:query var="userdb" >
	SELECT * FROM table	WHERE etc etc...%>'
	</sql:query>


And the query work... so I get what i need with the following:

<c:forEach items="${userdb.rows}" var="blogs" >
<tr>
<td> <c:out value="${blogs.title}" /> </td>
<td> <c:out value="${blogs.description}" /> </td>
<td> <c:out value="${blogs.surname}" /> </td>
<td> <c:out value="${blogs.email}" /> </td>
<td> <c:out value="${blogs.id_user}" /> </td>

</tr>
</c:forEach>


And so everythings works...
The problem is that the:

<td> <c:out value="${blogs.id_user}" /> </td>

contains an output that i want to forward to a page with a form so that I can get the form pre-filled with the id_user... I tried with:

<c:set var="id_user" value="${blogs.id_user}" />


...but when i go to the page that contain:

[...]
<input type="hidden" name="id_user" value="<% out.write(id_user); %>" />
[...]


nothing works and no variable is passed to the form... i get errors of course...
I don't know how to manage this variables from mysql to jsp, can somebody help me please?
I hope that what i wrote was not too confused!
Thanks to all!

Shella.

shella
Light Poster
28 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

just add ur datasource in to the context.xml of server add check , i hope it works finee
Hi all. I'm new with jsp and i'm just looking for create a login solution.
I use a mysql database and what i'm looking for is what follows:

Make a query to my sql database and then insert the output of one field in a variable.
I need this variable to pass the "id" to a form ... maybe with this code i will explain better.

/* part of the page with sql query

<sql:setDataSource
	url="jdbc:mysql://localhost/table"
	driver="com.mysql.jdbc.Driver"
	user="user"
	password="password" />
	
	<sql:query var="userdb" >
	SELECT * FROM table	WHERE etc etc...%>'
	</sql:query>


And the query work... so I get what i need with the following:

<c:forEach items="${userdb.rows}" var="blogs" >
<tr>
<td> <c:out value="${blogs.title}" /> </td>
<td> <c:out value="${blogs.description}" /> </td>
<td> <c:out value="${blogs.surname}" /> </td>
<td> <c:out value="${blogs.email}" /> </td>
<td> <c:out value="${blogs.id_user}" /> </td>

</tr>
</c:forEach>


And so everythings works...
The problem is that the:

<td> <c:out value="${blogs.id_user}" /> </td>

contains an output that i want to forward to a page with a form so that I can get the form pre-filled with the id_user... I tried with:

<c:set var="id_user" value="${blogs.id_user}" />


...but when i go to the page that contain:

[...]
<input type="hidden" name="id_user" value="<% out.write(id_user); %>" />
[...]


nothing works and no variable is passed to the form... i get errors of course...
I don't know how to manage this variables from mysql to jsp, can somebody help me please?
I hope that what i wrote was not too confused!
Thanks to all!

Shella.

pradeep42
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
 

Well done you solved 2 years old mystery.

Thread closed

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You