struts2 页面取值_struts2.1如何在页面上取值?
//在Action中:
//添加更接
public String LinkUpdataPage()
{
String NewID= ServletActionContext.getRequest().getParameter("NewsID");
System.out.println("ID:::"+NewID);
NewsBean newsInfo= (NewsBean) newsDao.findAllByID(NewID);
if(newsInfo!=null)
{
ServletActionContext.getContext().getSession().put("newsInfo", newsInfo);
System.out.println("Result:"+newsInfo);
return "updateNewsPage";
}else{
return "fail";
}
}
頁面上的代碼:
新聞管理:
新聞標題::????????
問題:在頁面上取不到作用域的值:newsInfo,是不是我的取法不對?
如何在頁面上取Action中的各作用域的値?request session
問題補充:
我說錯了,是這樣:就是取不到值,
新聞標題::????????
這樣不行嗎name="new_title" value="${newsInfo.new_title}"? > ?
問題補充:
//在Action中:
//添加更接
public String LinkUpdataPage()
{
String NewID= ServletActionContext.getRequest().getParameter("NewsID");
System.out.println("ID:::"+NewID);
NewsBean newsInfo= (NewsBean) newsDao.findAllByID(NewID);
if(newsInfo!=null)
{
ServletActionContext.getContext().getRequest().put("newsInfo", newsInfo);
System.out.println("Result:"+newsInfo);
return "updateNewsPage";
}else{
return "fail";
}
}
頁面上的代碼:
新聞管理:
新聞標題::
這樣取不到值。。。。。
問題補充:
總算出來了,是這樣寫就可以:
//---------Action code
//添加更接
public String LinkUpdataPage()
{
String NewID= ServletActionContext.getRequest().getParameter("NewsID");
System.out.println("ID:::"+NewID);
NewsBean newsInfo= (NewsBean) newsDao.findAllByID(NewID);
if(newsInfo!=null)
{
ServletActionContext.getContext().getSession().put("newsInfo", newsInfo);
ServletActionContext.getRequest().setAttribute("newsInfo", newsInfo);
return "updateNewsPage";
}else{
return "fail";
}
}
//----------Page code
更新新聞:
新聞標題:
新聞內容:
新聞類型:
總結
以上是生活随笔為你收集整理的struts2 页面取值_struts2.1如何在页面上取值?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: go语言复数包_go语言学习之包和变量详
- 下一篇: vue 多个click_vue中touc