File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptlet in STRUTS 2

 
Kartik Tal
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi am using a scriptlet in JSP of Struts 2, but am not able to get the value in textfield. Below is the code which i have used



Its showing an error like "Missing quotes for attribute value"
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should try <s:textfield value="<%=str %>">.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely the tags in Struts2 support EL so you should avoid scriptlets and do something like this instead:

<s:textfield value="${tDate}" />

I'd also be a bit surprised if this really isn't even the best way. Most tag libraries in the popular frameworks pull in data from the request and bind it back automatically. But I don't know enough about Struts2 to say how in this case. But the above example *should* work.
 
Kartik Tal
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

I tried with your statement but its giving error like
<s:textfield value="${tDate}" name="toDate" id="toDate" />


org.apache.jasper.JasperException: /jsp/ToDate.jsp(4,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the value is an action property just use OGNL. If it's really in the request then also use OGNL.
 
Kartik Tal
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi david, i have both ways like

<s:textfield value="${tDate}" name="toDate" id="toDate" />

and




Both none of the things had worked, if you dont mind could you give the exact syntax how to use OGNL
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
 
Kartik Tal
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
I tried with the OGNL also but it is not displaying any value, instead of value it is displaying the code.
But if am using property instead of textfield its working fine.




I had used both the ways but still no luck. Instead of value its displaying "#request.hello"

But its working for property




 
sandy safikri
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii i have a same problem how to get struts 2 property?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try wrapping the expression in the OGNL escape %{}.

@Sandy: what's a "Struts 2 property"? In other words, be specific. Better yet, start new threads for new topics, and TellTheDetails.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Kartik: wait, are you trying to access *parameters*?! Use #parameters then, otherwise you're attempting to access *attributes*. But in general you should never need to access a request parameter directly in a JSP-why are you doing this?
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:@Kartik: wait, are you trying to access *parameters*?! Use #parameters then, otherwise you're attempting to access *attributes*. But in general you should never need to access a request parameter directly in a JSP-why are you doing this?

I hope Kartik is still not stuck with this problem after almost 1 year ...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL, hadn't noticed Sandy woke a sleeper.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic