<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 一、存儲新聞dao方法 在NewsDao.java中新增存儲新聞的saveOrupdate方法 ~~~ public void saveOrupdate(News news){ getSession().saveOrUpdate(news); } ~~~ ### 二、存儲新聞service方法 在NewsService.java中新增存儲新聞的saveOrupdate方法 ~~~ public void saveOrupdate(News news){ newsDao.saveOrupdate(news); } ~~~ ### 三、存儲新聞action 讓NewsAction實現ModelDriven和Preparable接口,并實現其抽象方法。 ~~~ package cn.ac.ucas.action; import java.util.Map; import org.apache.struts2.interceptor.RequestAware; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import com.opensymphony.xwork2.Preparable; import cn.ac.ucas.form.News; import cn.ac.ucas.service.NewsService; public class NewsAction extends ActionSupport implements RequestAware, ModelDriven<News>, Preparable { private static final long serialVersionUID = 1L; private Map<String, Object> request; private NewsService newsService; private News model; @Override public void setRequest(Map<String, Object> arg0) { // TODO Auto-generated method stub this.request = arg0; } public void setNewsService(NewsService newsService) { this.newsService = newsService; } public String list() { // 新聞列表,獲取全部新聞 request.put("newslist", newsService.getAllNews()); return "list"; } public String save() { // 存儲新聞 // System.out.println(model); newsService.saveOrupdate(model); return "save"; } public String post() { // 跳轉到發布新聞頁面 return "post"; } @Override public News getModel() { // TODO Auto-generated method stub return model; } @Override public void prepare() throws Exception { // TODO Auto-generated method stub } public void prepareSave() { model = new News(); } } ~~~ ### 四、配置struts 修改struts.xml,使用新的攔截器棧 ~~~ <package name="default" namespace="/" extends="struts-default"> <!-- 定義新的攔截器,配置prepare攔截器棧的alwaysInvokePrepare參數值為false --> <interceptors> <interceptor-stack name="sshStack"> <interceptor-ref name="paramsPrepareParamsStack"> <param name="prepare.alwaysInvokePrepare">false</param> </interceptor-ref> </interceptor-stack> </interceptors> <!-- 使用新的攔截器棧 --> <default-interceptor-ref name="sshStack"></default-interceptor-ref> <action name="news-*" class="newsAction" method="{1}"> <result name="list">/WEB-INF/newslist.jsp</result> <result name="post">/WEB-INF/newspost.jsp</result> <result name="save" type="redirect">/news-list</result> </action> </package> ~~~ 訪問news-post跳到/WEB-INF/newspost.jsp發布新聞,訪問news-save存儲新聞到數據庫并重定向到新聞列表頁。 ### 五、編寫前端頁面 在index.jsp加入一行,點擊中后跳轉至/WEB-INF/newspost.jsp ~~~ <a href="news-post">發布新聞</a> ~~~ newspost.jsp ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <s:form action="news-save" method="post"> <s:textfield name="title" label=" 新聞標題"></s:textfield> <s:textfield name="author" label="新聞作者"></s:textfield> <s:textfield name="source" label="新聞來源"></s:textfield> <s:textfield name="posttime" label="發布時間"></s:textfield> <s:textfield name="content" label="新聞內容"></s:textfield> <s:submit value="錄入"></s:submit> </s:form> </body> </html> ~~~ 錄入界面: ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdda65756.jpg "") 新聞列表頁: ~~~ <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>新聞列表</title> <style type="text/css"> body { margin: 0px; padding: 0px; width: 800px; margin: 30px auto; } .newslist h2 { text-align: center; } .newsinfo { text-align: center; } .newscontent { text-indent: 2em; } .newscontent a { display: block; float: right; } </style> </head> <body> <s:iterator value="#request.newslist"> <div class="newslist"> <h2>${title}</h2> <p class="newsinfo">${author}${source}${posttime}</p> <p class="newscontent">${content}</p> <hr> </div> </s:iterator> </body> </html> ~~~ ![這里寫圖片描述](https://box.kancloud.cn/2016-02-26_56cfbdda95499.jpg "")
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看