日期:2014-05-20  浏览次数:20643 次

如何在JSP页面得到值
我用的是SSH 使用了hibernate关系映射,想通过搜索城市然后查询出对应城市里的所有学校,那么在页面中应该怎样得到action中查出来的学校的值,高手们帮帮!!

------解决方案--------------------
给个最原始方法

action :request.setAttribute("cityname","shanghai");
jsp :<%=request.getAttribute("cityname")%>

struts2中有比较好的方法



------解决方案--------------------
用request来传递
------解决方案--------------------
用request请求对象传值啊!!
------解决方案--------------------
探讨
用request请求对象传值啊!!

------解决方案--------------------
查詢出所有學校放到list
request.setAttribute("school",schoollist);
葉面再用 
list = request.getAttribute("school")
------解决方案--------------------
用AJAX啊。。。呵呵,没有JAVA代码
------解决方案--------------------
放入list之中然后request.set...() 在用logic:iterate显示
------解决方案--------------------
[code=JScript][/code]

/**
 * @author Nicholas
 */
var req;
function Change_Select() {
var cid = document.getElementById("countyid").value;
var url = "./select?cid=" + cid;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else {
if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}
if (req) {
req.open("GET", url, true);

req.onreadystatechange = callback;
req.send(null);
}
}

function callback() {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessage();
} else {
alert("无法得到描述信息:" + req.statusText);
}
}
}
//½âÎö·µ»ØxmlµÄ·½·¨
function parseMessage() {
var xmlDoc = req.responseXML.documentElement;
var xSel = xmlDoc.getElementsByTagName("select");


var street = document.getElementById("street.streetid");


street.options.length = 0;

for (var i = 0; i < xSel.length; i++) {
var xText = xSel[i].childNodes[0].firstChild.nodeValue;

var xValue = xSel[i].childNodes[1].firstChild.nodeValue;
  
var option = new Option(xText, xValue);

try {
street.add(option);
}
catch (e) {
}
}
}


------解决方案--------------------
action :request.setAttribute("cityname","shanghai"); 
jsp : <%=request.getAttribute("cityname")%> 
用这个就可以了
------解决方案--------------------
EL表达式:
城市类.学校属性
当然还要迭代下
------解决方案--------------------
探讨
在页面中不出现Java代码,用struts2来实现,高手们给点办法吧!!

------解决方案--------------------
没接触过stucts2,不过如果用hibernate的话你可以用一个多对多关系映射到数据库然后通过stucts1.1来传值或者直接servlet过去.

和用户权限原理一样.我的理解
------解决方案--------------------
探讨


/**
* @author Nicholas
*/
var req;
function Change_Select() {