struts的action怎么写

1. 关于struts2的 action怎么写 额 看不懂你说的哦
【struts的action怎么写】不过struts2中的action最普遍要继承ActionSupport这个类,而你们老师继承ServletRequestAware类反正我们用过,然后就是定义实体类,和借口的方法 。在spring中注入
struts2中的方法以public String +方法名(){return "111";}来进行操作 return 里面的字符串要和你struts2配置中的那个<result name="111">;/页面的位置</result>;中的name属性相同,你在登录页面的form中调用你写的“方法名”就进入方法中如果成功返回“111”就会进入你所设置的页面位置 。
2. List 查询struts1的Action怎么写 struts.xml: &lt;action path="/user" scope="request" parameter="f"
type="com.manage.struts.action.sysmanage.UserManageAction"&gt;
&lt;forward name="success" path="" /&gt;
&lt;/action&gt;
action : extends DispatchAction
public ActionForward loginOut(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
request.getSession().removeAttribute("userSession");
request.getSession().invalidate();
HashMap&lt;String, Object&gt; jsonMap = new HashMap&lt;String, Object&gt;();
jsonMap.put("success", true);
jsonMap.put("message","退出登录成功");
JSONObject json = new JSONObject();
json.putAll(jsonMap);
Writer writer = response.getWriter();
writer.write(json.toString());
writer.flush();
return mapping.findForward("");
}
3. struts2中一个action中实现多个功能应该怎么写 可以在action中写多个你需要的方法..然后在struts.xml中为这个action类配置多个你可以给这些起不同名字,然后用method属性制定要执行哪个方法 。
例如:/login.jsp/Login.jsp/welcome.jsp例如上面的配置就是为LoginAction这个action类配置了2个而起了不同的名字其中第一个指明了method,用户请求forwardLogin时就会调用LoginAction中的forward()方法第二个没有明了method,用户请求login时就会调用LoginAction中默认的execute()方法 。
4. struts2中action里面怎么写一个方法直接查询数据库数据, 先写的DAO:public List<FileModel> findAll()
{
Connection con = null ;
PreparedStatement ps = null ;
FileModel file = null ;
ResultSet rs = null;
List<FileModel> set = null ;
try
{
con = DBconnection.getConnection();
String sql = "select * from file ;
ps = con.prepareStatement(sql);
set = new LinkedList<FileModel>();
rs = ps.executeQuery() ;
while(rs.next())
{
file = new FileModel();
file.setFilepath(rs.getString(1));
file.setFiletime(rs.getTimestamp(2));
file.setFileintroduce(rs.getString(3));
file.setFilediscuss(rs.getString(4));
file.setFilescore(rs.getFloat(5));
file.setFiletype(rs.getString(6));
file.setDirection(rs.getString(7));
file.setFileid(rs.getInt(8));
file.setFilename(rs.getString(9));
set.add(file);
}
}
catch(SQLException e)
{
throw new RuntimeException(e.getMessage(),e);
}
finally
{
DBconnection.free(rs, ps, con);
}
return set;
}
在action中调用DAO:
public class FindAction extends ActionSupport {
private Dao dao = new Dao();
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
LinkedList<FileModel> modelSet = (LinkedList<FileModel>) dao.findAll();
if (modelSet!=null){
System.out.println(modelSet);
ActionContext.getContext().getSession().put("msg", modelSet);
return SUCCESS;}
else
return ERROR;
}
}

struts的action怎么写