教育改变生活

标题: MVC项目新闻系统:详细信息 [打印本页]

作者: 却尘    时间: 2023-6-29 12:56
标题: MVC项目新闻系统:详细信息
新闻系统-详细信息
页面效果:
1、前端:showdetail.jsp
<%@page import="Service.ArticleBiz"%>
<%@page import="POJO.Article"%>
<%@page import="com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import"%>
    <%@page language = "java" import = "java.util.*" pageEncoding = "utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName()+":"+
    request.getServerPort() + path +"/";
   %>
   <% Article article = (Article)request.getAttribute("article"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
修改新闻<br>
     <input type = "hidden" name = "id" value = "<%= article.getId()%>"/>标题
     <%= article.getTitle()%><br>作者
     <%= article.getAuthor()%><br>内容
     <%= article.getContent() %><br>
<a href = "ArticleShowList">返回新闻列表</a>
</body>
</html>
2、控制层(Controller)代码
ArticleShow .java
package Controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import POJO.Article;
import Service.ArticleBiz;
@WebServlet("/ArticleShow")
public class ArticleShow extends HttpServlet  {
        @Override
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                int id = Integer.parseInt(request.getParameter("id"));
                ArticleBiz articleBiz =new ArticleBiz();
                Article  article = articleBiz.get(id);
                request.setAttribute("article", article);
                request.getRequestDispatcher("showdetail.jsp").forward(request, response);
        }
}






欢迎光临 教育改变生活 (http://bbs.goldoar.com/) Powered by Discuz! X3.2