HttpSession session = ServletActionContext.getRequest().getSession();
SelectSql sel = new SelectSql();
System.out.println(sel.selectNewsAll().size());
session.setAttribute("newslist", sel.selectNewsAll());
return SUCCESS;
将list<News>保存进jsp中 ,如何从jsp中取出来 ,如下:
<s:iterator value="#session.newslist" status="statu" id="item">
<s:property value="title" /><s:property value="content" />
</s:iterator>
进入一个页面直接调用action
放在《body》下
<s:action name="allnews" executeResult="false"></s:action>
myeclipse jsp快速注释 ctrl+shift+c
struts2 表单验证
<form action="houtai/userLogin" name="loginForm" method="post">
<td width="50%" valign="bottom"><s:textfield name="user.userName" id="username" size="20" maxlength="20"/></td>
</tr>
<tr>
<td> </td>
<td valign="bottom"><s:password name="user.password" size="22" maxlength="20"/></td>
</tr>
<area shape="rect" coords="280,8,335,34" href="#" onClick="return checkForm();">
<area shape="rect" coords="357,8,413,35" href="#" onClick="return reset();">
</map></form>
<script type="text/javascript">
function checkForm() {
var username=document.getElementById("username").value;
if(username=="" ){
alert("用户名不能为空!");
document.getElementById("username").focus();
return false;
}
if(username.length<4 || username.length>10){
alert("用户名长度在4到10之间");
return false;
}else{
document.loginForm.submit();
}
}
struts2 namespace 配置 要以"/" 开头,否则报错 无法找到action mapping
数据库出现乱码 ,在连接时指定链接字符
jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
struts2 比如要删除一个结果集,如删除一条新闻,根据<a href="delNews?newId=<s:property value='newId'/>"
οnclick="return confirm('确认删除?')">删除</a></td>
来传入newId给action 删除,那么传入action的方式有
String param = ServletActionContext.getRequest().getParameter("newId");
<s:textfield name="news.title" value="<s:property value="request.news.title" >"/> 无法嵌套struts2 标签,会报错
正确的做法是,直接赋值
<s:textfield name="news.title" value="%{#request.news.title}" />