<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'addTopic.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="https://www.ctyun.cn/portal/link.html?target=css%2Fcss.css"/> </head> <body> <form action="admin/addTopic_action.jsp" method="post"> <table> <caption>添加主题</caption> <tr><td>主题名称</td><td><input type="text" name="tname"/></td></tr> <tr> <td><input type="submit" value="提交"/></td> <td><input type="reset" value="重置"/></td> </tr> </table> </form> </body> </html>
增加主题的action页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="com.news.dao.*,com.news.dao.impl.*,com.news.entity.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'addTopic_action.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <body> <% //接收从页面传过来的值; request.setCharacterEncoding("utf-8"); String tname=request.getParameter("tname"); TopicDao td=new TopicDaoImpl(); int result=td.addTopic(tname); if(result>0){ response.sendRedirect("showAllTopic.jsp"); }else{ response.sendRedirect("error.jsp"); } %> </body> </html>增加新闻页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'addNews.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="https://www.ctyun.cn/portal/link.html?target=css%2Fcss.css"/> </head> <body> <form action="admin/addNews_action.jsp" method="post"> <table> <tr><td>主题</td> <td><select name="tid"> <% TopicDao td=new TopicDaoImpl(); List<Topic>topices=td.getAllTopic(); for(Topic topic:topices){ %> <option value="<%=topic.getId()%>"><%=topic.getTname() %></option> <% }%> </select></td> </tr> <tr><td>标题</td><td><input type="text" name="title"></td></tr> <tr><td>作者</td><td><input type="text" name="author"></td></tr> <tr><td>摘要</td><td><textarea rows="10" cols="20" name="summary"></textarea></td></tr> <tr><td>内容</td><td><textarea rows="13" cols="50" name="ncontent"></textarea></td></tr> <tr><td colspan="2"> <input type="submit" value="提交"> <input type="reset" value="重置"></td> </tr> </table> </form> </body> </html>增加新闻的action
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'addNews_action.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <body> <% //获取相关数据,先设置相关字符集编码 request.setCharacterEncoding("utf-8"); String tsid=request.getParameter("tid"); int tid=Integer.parseInt(tsid); String title=request.getParameter("title"); String author=request.getParameter("author"); String summary=request.getParameter("summary"); String ncontent=request.getParameter("ncontent"); News news=new News(); news.setTid(tid); news.setTitle(title); news.setAuthor(author); news.setSummary(summary); news.setNcontent(ncontent); NewsDao nd=new NewsDaoImpl(); int result=nd.addNews(news); if(result>0){ response.sendRedirect("showAllNews.jsp"); }else{ response.sendRedirect("error.jsp"); } %> </body> </html>注册用户页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'register_action.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" type="text/css" href="https://www.ctyun.cn/portal/link.html?target=css%2Fcss.css"/> </head> <body> <form action="admin/register_action.jsp" method="post"> <table> <tr> <td>账号:</td> <td><input type="text" name="username"/></td> </tr> <tr> <td>密码:</td> <td><input type="password"name="userpwd"/></td> </tr> <tr> <td>邮箱:</td> <td><input type="text" name="email"/></td> </tr> <tr> <td>地址:</td> <td><input type="text" name="address"/></td> </tr> <tr> <td>爱好:</td> <td><input type="checkbox" name="hobby" value="reading"/>看书 <input type="checkbox" name="hobby" value="program"/>编程 <input type="checkbox" name="hobby" value="sports"/>体育 <input type="checkbox" name="hobby" value="fince"/>财经 <input type="checkbox" name="hobby" value="broad"/>直播 <input type="checkbox" name="hobby" value="game"/>游戏 </td> </tr> <tr> <td><input type="submit" value="注册"/></td> <td><input type="reset" value="取消"/></td> </tr> </table> </form> </body> </html>
注册用户action页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B"> <title>My JSP 'register_action.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <input type="checkbox" name="hobby"/> </head> <body> <% //设置请求的字符集合,在传输数据之前进行 request.setCharacterEncoding("utf-8"); String username=request.getParameter("username"); String userpwd=request.getParameter("userpwd"); String email=request.getParameter("email"); String address=request.getParameter("address"); String []hobbys=request.getParameterValues("hobby"); String hobby=""; //变量字符串 for(int i=0;i<hobbys.length;i++){ hobby=hobbys[i]+","; } UserDao ud=new UserDaoImpl(); boolean flag=ud.saveUser(username,userpwd,email,address,hobby); if(flag) response.sendRedirect("register_success.jsp"); else response.sendRedirect("register_error.jsp"); %> </body> </html>
注册成功页面和失败页面省略!读者自行补充