JSP新闻系统之五 增加操作
【摘要】
增加主题
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %>
<%
Str...
<%@ 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="<%=basePath%>">
<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="css/css.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="<%=basePath%>">
<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="<%=basePath%>">
<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="css/css.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>
<%@ 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="<%=basePath%>">
<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="<%=basePath%>">
<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="css/css.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>
<%@ 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="<%=basePath%>">
<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>
文章来源: aaaedu.blog.csdn.net,作者:tea_year,版权归原作者所有,如需转载,请联系作者。
原文链接:aaaedu.blog.csdn.net/article/details/53053030
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)