有一个页面,提供查询功能,选择书籍的名称,输入书籍名字,点击查询,弹出查询结果窗口,其代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String p = request.getContextPath();
String name =request.getParameter("queryName");
String value =request.getParameter("queryValue");
String url = "search.action?queryName="+name+"&queryValue="+value+"";
//request.setAttribute("url",url);
%><head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}table thead tr th {
border: 1px solid black;
padding: 3px;
background-color: #cccccc;
background-color: expression(this.rowIndex % 2 == 0 ? "#FFFFFF" : "#EEEEEE");
}table tbody tr td {
border: 1px solid black;
padding: 3px;
}
.trs{
background-color: expression(this.rowIndex % 2 == 0 ? "#FFFFFF" : "#EEEEEE");
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table cellspacing="0" align="center">
<thead>
<tr>
<th>ID</th>
<th>书名</th>
<th>作者</th>
<th>出版社</th>
<th>出版日期</th>
<th>ISNB</th>
<th>页数</th>
<th>价格</th>
<th>内容提要</th>
</tr>
</thead>
<tbody>
<s:iterator value="availableItems">
<tr class="trs">
<td><s:property value="bookId"/></td>
<td><s:property value="bookName"/></td>
<td><s:property value="bookAuthor"/></td>
<td><s:property value="bookPublish"/></td>
<td><s:date name="bookDate" format="yyyy-MM-dd" /></td>
<td><s:property value="bookIsbn" /></td>
<td><s:property value="bookPage" /></td>
<td><s:property value="bookPrice"/></td>
<td>&nbsp;<s:property value="bookContent"/></td>
</tr>
</s:iterator>
<tr align="right">
<td colspan="9">
共<s:property value="totalRows" />行&nbsp;
第<s:property value="currentPage"/>页&nbsp;
共<s:property value="pager.getTotalPages()"/>页&nbsp;
<a href="<s:url value=url>
<s:param name="currentPage" value="currentPage"/>
<s:param name="pagerMethod" value="'first'"/>
</s:url>">首页</a><a href="<s:url value=url>
<s:param name="currentPage" value="currentPage"/>
<s:param name="pagerMethod" value="'previous'"/>
</s:url>">上一页</a>
<a href="<s:url value=url>
<s:param name="currentPage" value="currentPage"/>
<s:param name="pagerMethod" value="'next'"/>
</s:url>">下一页</a>
<a href="<s:url value=url>
<s:param name="currentPage" value="currentPage"/>
<s:param name="pagerMethod" value="'last'"/>
</s:url>">尾页</a>
</td>
</tr> 
</tbody>
</table>
</body>
</html>
现在问题是<a href="<s:url value=url>中的url获取不到上面的地址,试了几种方式都不可以,请问如何在struts2 标签中引用JAVA变量(不可以的话用什么方式来取)怎么写,谢谢了

解决方案 »

  1.   

    可以使用EL表达式或者ognl
      

  2.   

    用el或者ognl,OGNL是spring中有一个包,你导入那个包就行了。
      

  3.   

    能帮我写下不,自己也试了,但总是不对,尤其是放在<s:url value=url>,就更不对了,谢谢了同志们,这个问题已经困扰我一晚上了
      

  4.   

    request.setAttribute("url",url);
    要把注释放开。
    <a href="<s:url value=url>
    <s:param name="currentPage" value="currentPage"/>
    <s:param name="pagerMethod" value="'first'"/>
    </s:url>">首页</a>
    其中value=url中的url两边要加引号。
    value="'first'"两边的单引号要去掉。
      

  5.   

    不行,点击的时候该url在IE上无法显示链接地址,只能显示“url”