Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL getparameter to int  RSS feed

 
Zet Su
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello together,

JSTL makes me crazy! I want to do something very simple but i cant. I get parameter from index.jsp an want to insert these parameter in an SQL table but i always get the error, that the variable "id" is char and the tablerow needs integer.

this is my code:
<c:set var="id" value= "<%= request.getParameter("id") %>"/>
<c:set var="name" value= "<%= request.getParameter("name") %>"/>
<c:set var="email" value= "<%= request.getParameter("email") %>"/>
<c:set var="titel" value= "<%= request.getParameter("titel") %>"/>
<c:set var="inhalt" value= "<%= request.getParameter("inhalt") %>"/>

<sql:update dataSource="${snapshot}" var="result">
INSERT INTO APP."forum" ("ANTWORT_ID","ANTWORT","NAME","MAIL","TITEL","INHALT","ZEIT") VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp)
</sql:update>

Error i get:
javax.servlet.ServletException:
INSERT INTO APP."forum" ("ANTWORT_ID","ANTWORT","NAME","MAIL","TITEL","INHALT","ZEIT") VALUES('3',false,'test','test','test','test',current_timestamp)
: Spalten vom Typ 'INTEGER' dürfen keine Werte des Typs 'CHAR' enthalten.

I hope someone here can help me :*>
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing it's the number you are trying to INSERT for ANTWORT_ID.
You've put quotes around it.
 
Zet Su
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello dave,

do you mean the quotes here <c:set var="id" value= "<%= request.getParameter("id") %>"/> ?
or do you mean them here
VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp) ?

When i use c:out and print the request.getParameter or "id", there is only a number (without quotes!).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth are you mixing JSTL and EL with scriptlet expressions? That's nuts.

Instead of <c:set var="id" value= "<%= request.getParameter("id") %>"/> just use ${param.id}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it is not advisable to use the sql JSTL tags in production JSP pages. Follow correct MVC.
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zet Su wrote:Hello dave,

do you mean the quotes here <c:set var="id" value= "<%= request.getParameter("id") %>"/> ?
or do you mean them here
VALUES('${id}',false,'${name}','${email}','${titel}','${inhalt}',current_timestamp) ?

When i use c:out and print the request.getParameter or "id", there is only a number (without quotes!).


Here:

You've added quotes.

But you should listen to Bear, the JSP is not the place to be doing any of this.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!