tags:

views:

12

answers:

2

test.jsp:

%%%%%%%%%%%%%

< s:property value="#parameters.type"/> 

 < s:if test="#parameters.type == 1">

   < select>

 < option value="-1">
  请选择
 < /option>
 < option value="1" selected>
         收件箱
 < /option>
 < option value="2">
  发件箱
 < /option>
    < /select>
< /s:if>

%%%%%%%%%%%%%%

when this page is accessed by test.jsp?type=1 the s:if test is false, so the select list is not showed. Can somebody tell me why? thanks!

A: 

I hope you understand that your code is not good struts2 practice. That's not the way Struts2 is supposed to be used normally. Your http parameters should normally be mapped to your action fields, and (after your action has done its work) your jsp should show the results pulling them from the same action. Normally. And normally, you should not need to access http parameters in your jsp, nor do any logic (except for very trivial ones).

Anyway, perhaps the problem in your test is that #parameters.type is a raw string, and you are comparing it to a number. (That's one of the many problems of violating the normal Struts2 flow - the convertion from plain strings to more meaningful types is normally done in that mapping, by the param interceptor. The problem would not arise is you had a proper integer 'type' field in your action, and in your jsp you ask for it) Did you try #parameters.type == '1' ?

leonbloy
yes, i've also tried #parameters.type == '1' , but it wont work either.
A: 

I've solved the problem. just substitute the "#parameters.type" with "#parameters.type[0]". Then the test works!

Thats because struts2 treat the parameters form URL as an array.