我的list
<body>
  <h1 align="center">新闻列表</h1>
  <h2><a href="${pageContext.request.contextPath }/news/action_addUI.action">新闻添加</a></h2>
   <table border="1" width="80%" align="center">
   <tr>
   <th>主题</th>
   <th>内容</th>
   <th>发布时间</th>
   <th>所属分类</th>
   <th colspan="2">操作</th>
   </tr>
    <s:iterator value="news">
     <tr>
     <td><s:property value="theme"/></td>
     <td><s:property value="content"/></td>
     <td align="right"><s:property value="publishtime"/></td>
     <td><s:property value="mold"/></td>
     <td><a href="${pageContext.request.contextPath }/news/action_updateUI.action?id=<s:property value="id"/>">修改</a></td>
     <td><a href="${pageContext.request.contextPath }/news/action_delete.action?id=<s:property value="id"/>">删除</a></td>
     </tr>
    </s:iterator>
</table>
  </body>action层:@Resource NewsService newsService;
private String message;
private List<News> news;
private News n;
/**
 * 新闻列表显示
 * @return
 */
public String list(){
this.news = newsService.getNews();
return "list";
}
/**
 * 新闻添加界面
 * @return
 */
public String addUI(){
return "add";
}
/**
 * 新闻添加
 * @return
 */
public String add(){
this.newsService.save(this.n);
this.message="添加成功";
return "message";
}
/**
 * 新闻删除
 * @return
 */
public String delete(){
this.newsService.delete(this.n.getId());
this.message="删除成功";
return "message";
}
/**
 * 新闻修改界面
 * @return
 */
public String updateUI(){
return "update";
}
/**
 * 新闻修改
 * @return
 */
public String update(){
this.newsService.getNews(this.n.getId());
this.newsService.update(this.n);
this.message="修改成功";
return "message";
}


public News getN() {
return n;
}
public void setN(News n) {
this.n = n;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<News> getNews() {
return news;
}
public void setNews(List<News> news) {
this.news = news;
}
}
修改
<s:form action="action_update" namespace="/news">
<p>主题:<s:textfield name="n.theme"/></p>
内容:<s:textarea name="n.content" cols="30" rows="8"/><br />
发布时间:<s:textfield name="n.publishtime"/>
所属分类:<s:textfield name="n.mold"/>
<p>
<input type="submit" value="修改"/>
</p>
</s:form>
我该怎么写 才能得到 id 并且完成 删除 修改 

解决方案 »

  1.   

    String id =request.getParameter("id")news/action_delete.action?id=<s:property value="id"/>你这个地方传了一个Id参数,得到他就可以了
      

  2.   

    在action的delete函数里加入
    String id =request.getParameter("id");
    打印下看看id有没有值,有就
    this.newsService.delete(id);
    否则就
      

  3.   

    给你参考我的代码:
    <s:iterator value="pageBean.list" var="fawen">
    <tr class="td_x" height="20px">
    <td class="td_x" style="height: 10px" align="center"
    width=60><s:property value="fawenNumber" /></td>
    <td class="td_x" align="center" width=60><a style="color:#000000;text-decoration:none"
    href="documentfindFawenById.action?fawenId=${id }"><s:property
    value="title" /></a></td>
    <td class="td_x" align="center" width=70>&nbsp&nbsp&nbsp&nbsp<s:property
    value="draftsman" /></td>
    <td class="td_x" align="center" width=200 ><s:property
    value="createTime" /></td>
    <td></td>
    <!--  <td class="td_08" id="td_edit" width=60 align="center"
    value="${id}"><a
    href="userfindUser.action?userId=${id}"><img
    src="css/images/z2/edit.png"></a></td> -->
    <td class="td_08" id="td_edit" width=60 align="center">
    <img alt="" src="css/images/z2/edit.png" onclick="edit(${id});">
    </td>
    </tr>
    </s:iterator>
    ......
    function edit(id) {
         window.self.location = "documentfindFawenById.action?fawenId=" + id;
    }
    祝你好运!
      

  4.   

    我觉着是不是你的Action写错了,或者传参时的url有问题
      

  5.   

    对了  应该是
    ><a href="${pageContext.request.contextPath }/news/action_delete.action?
    n.id=<s:property value="id"/>">删除</a></td>
      

  6.   

    否则就在你的Action里面写个  属性id 并写上 get set方法 
    然后 service.delete(id);
      

  7.   


    +1  我也觉得是这个原因。 不过你最好还是在action里定义一个id属性,并配置get/set方法吧。
    就可以再action里直接使用id了
      

  8.   

    昨天 我有改了改 这是我 最后的 代码
    package com.bothtimes.web;import java.util.List;import javax.annotation.Resource;import com.bothtimes.bean.News;
    import com.bothtimes.service.NewsService;public class NewsAction {
    @Resource NewsService newsService;
    private String message;
    private List<News> news;
    private News n;
    private Integer id;

    /**
     * 新闻列表显示
     * @return
     */
    public String list(){
    this.news = newsService.getNews();
    return "list";
    }
    /**
     * 新闻添加界面
     * @return
     */
    public String addUI(){
    return "add";
    }
    /**
     * 新闻添加
     * @return
     */
    public String add(){
    this.newsService.save(this.n);
    this.message="添加成功";
    return "message";
    }
    /**
     * 新闻删除
     * @return
     */
    public String delete(){
    this.newsService.delete(this.getId());
    this.message="删除成功";
    return "message";
    }
    /**
     * 新闻修改界面
     * @return
     */
    public String updateUI(){
    this.newsService.getNews(this.getId());
    return "update";
    }
    /**
     * 新闻修改
     * @return
     */
    public String update(){
    this.newsService.update(this.n);
    this.message="修改成功";
    return "message";
    }


    public News getN() {
    return n;
    }
    public void setN(News n) {
    this.n = n;
    }
    public String getMessage() {
    return message;
    }
    public void setMessage(String message) {
    this.message = message;
    }
    public List<News> getNews() {
    return news;
    }
    public void setNews(List<News> news) {
    this.news = news;
    }
    public Integer getId() {
    return id;
    }
    public void setId(Integer id) {
    this.id = id;
    }
    }
    现在我的 删除 没有问题了  但是 不知道为什么我的 修改的 功能是 添加 我就不知道了
      

  9.   

    这样写应该也对哦 
    但是我那样写 应该也没有错吧 n.id  和 id 我觉得 都是得到的 此条记录的 id是把
      

  10.   

    在action中添加一个id属性,提供get/set方法;在action中就可以自动获得id值