期刊论文在线投稿审稿系统②(投稿人功能页-'我要投稿'功能的实现)
作者:互联网
一、‘我要投稿’功能
二、效果如下
三、代码如下
Contribute.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>投稿人功能页</title> 8 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 9 <script src=".//layui/layui.all.js"></script> 10 <script src=".//layui/layui.js"></script> 11 <script type="text/javascript"> 12 //JavaScript代码区域 13 layui.use('element', function() { 14 var element = layui.element; 15 }); 16 </script> 17 </head> 18 <body class="layui-layout-body"> 19 20 <div class="layui-layout layui-layout-admin"> 21 <div class="layui-header"> 22 <div class="layui-logo"> 23 <% 24 String identity = (String) session.getAttribute("identity"); 25 out.print(identity); 26 %> 27 功能页欢迎 28 <% 29 String username = (String) session.getAttribute("username"); 30 out.print(username); 31 %> 32 </div> 33 </div> 34 35 <div class="layui-side layui-bg-black"> 36 <div class="layui-side-scroll"> 37 <!-- 左侧导航 --> 38 <ul class="layui-nav layui-nav-tree"> 39 <li class="layui-nav-item"><a href="Contribute_submit.jsp" 40 target="frame">我要投稿</a></li> 41 <li class="layui-nav-item"><a href="ContributeServlet?method=alter" 42 target="frame">修改稿件</a></li> 43 <li class="layui-nav-item"><a 44 href="ContributeServlet?method=withdraw" target="frame">退审意见</a></li> 45 <li class="layui-nav-item"><a 46 href="ContributeServlet?method=Check_The_Schedule" target="frame">查看进度</a></li> 47 <li class="layui-nav-item"><a 48 href="Contribute_alterpassword.jsp" target="frame">密码修改</a></li> 49 </ul> 50 </div> 51 </div> 52 <div class="layui-body"> 53 <!-- 内容主体区域 --> 54 <iframe name="frame" width="100%" height="100%" 55 style="border: 1px solid #CCC;"></iframe> 56 </div> 57 <div> 58 <div> 59 <input type="text" id="date" /> 60 </div> 61 </div> 62 </div> 63 64 </body> 65 </html>
Contribute_submit.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>我要投稿</title> 8 <link rel="stylesheet" href=".//layui/css/layui.css" media="all"> 9 <script src=".//layui/layui.all.js"></script> 10 <script src=".//layui/layui.js"></script> 11 </head> 12 <body> 13 <form class="layui-form" 14 action="ContributeServlet?method=submit" method="post"> 15 <div class="layui-form-item"> 16 <label class="layui-form-label">中文标题</label> 17 <div class="layui-input-block"> 18 <input type="text" name="ctitle" required lay-verify="required" 19 placeholder="请输入中文标题" autocomplete="off" class="layui-input"> 20 </div> 21 <div class="layui-form-mid layui-word-aux">(限100字以内)</div> 22 </div> 23 <div class="layui-form-item layui-form-text"> 24 <label class="layui-form-label">英文标题</label> 25 <div class="layui-input-block"> 26 <input type="text" name="etitle" required lay-verify="required" 27 placeholder="请输入英文标题" autocomplete="off" class="layui-input"> 28 </div> 29 <div class="layui-form-mid layui-word-aux">(限400个字符以内)</div> 30 </div> 31 <div class="layui-form-item"> 32 <label class="layui-form-label">中文摘要</label> 33 <div class="layui-inline"> 34 <input type="text" name="cabstract" required lay-verify="required" 35 placeholder="请输入中文摘要" autocomplete="off" class="layui-input"> 36 </div> 37 <div class="layui-form-mid layui-word-aux">(限300字以内)</div> 38 </div> 39 <div class="layui-form-item"> 40 <label class="layui-form-label">英文摘要</label> 41 <div class="layui-inline"> 42 <input type="text" name="eabstract" required lay-verify="required" 43 placeholder="请输入英文摘要" autocomplete="off" class="layui-input"> 44 </div> 45 <div class="layui-form-mid layui-word-aux">(限3000字符以内)</div> 46 </div> 47 <div class="layui-form-item"> 48 <label class="layui-form-label">中文关键字</label> 49 <div class="layui-inline"> 50 <input type="text" name="ckey" required lay-verify="required" 51 placeholder="请输入中文关键字" autocomplete="off" class="layui-input"> 52 </div> 53 <div class="layui-form-mid layui-word-aux">(限100字以内)</div> 54 </div> 55 <div class="layui-form-item"> 56 <label class="layui-form-label">英文关键字</label> 57 <div class="layui-inline"> 58 <input type="text" name="ekey" required lay-verify="required" 59 placeholder="请输入英文关键字" autocomplete="off" class="layui-input"> 60 </div> 61 <div class="layui-form-mid layui-word-aux">(限200个字符以内)</div> 62 </div> 63 <div class="layui-form-item layui-form-text"> 64 <label class="layui-form-label">稿件正文</label> 65 <div class="layui-input-block"> 66 <textarea name="content" placeholder="请输入稿件正文" 67 class="layui-textarea"></textarea> 68 </div> 69 </div> 70 <div class="layui-form-item"> 71 <label class="layui-form-label">投稿人</label> 72 <div class="layui-input-block"> 73 <input type="text" name="name" required 74 lay-verify="required" placeholder="请输入您的账号" autocomplete="off" 75 class="layui-input"> 76 </div> 77 </div> 78 <div class="layui-form-item"> 79 <div class="layui-input-block"> 80 <button class="layui-btn" lay-submit>立即提交</button> 81 <button type="reset" class="layui-btn layui-btn-primary">重置</button> 82 </div> 83 </div> 84 </form> 85 </body> 86 </html>
Story.java(在util文件下建立此java文件)
1 package util; 2 3 /** 4 * 稿件 5 * @author Administrator 6 * 7 */ 8 public class Story { 9 private String ctitle;//中文标题 10 private String etitle;//英文标题 11 private String cabstract;//中文摘要 12 private String eabstract;//英文摘要 13 private String ckey;//中文关键字 14 private String ekey;//英文关键字 15 private String content;//稿件内容 16 private String receiver;//接收方,方便查询相关状态 17 private String status;//稿件状态,1为OK,0为撤稿 18 private String name;//投稿人 19 public Story(String ctitle,String etitle,String cabstract,String eabstract,String ckey,String ekey,String content,String receiver,String status,String name) { 20 super(); 21 this.ctitle=ctitle; 22 this.etitle=etitle; 23 this.cabstract=cabstract; 24 this.eabstract=eabstract; 25 this.ckey=ckey; 26 this.ekey=ekey; 27 this.content=content; 28 this.receiver=receiver; 29 this.status=status; 30 this.name=name; 31 } 32 public Story(String ctitle, String etitle, String cabstract, String eabstract, String ckey, String ekey, 33 String content, String name) { 34 super(); 35 this.ctitle=ctitle; 36 this.etitle=etitle; 37 this.cabstract=cabstract; 38 this.eabstract=eabstract; 39 this.ckey=ckey; 40 this.ekey=ekey; 41 this.content=content; 42 this.name=name; 43 } 44 public String getCtitle() { 45 return ctitle; 46 } 47 public void setCtitle(String ctitle) { 48 this.ctitle = ctitle; 49 } 50 public String getEtitle() { 51 return etitle; 52 } 53 public void setEtitle(String etitle) { 54 this.etitle = etitle; 55 } 56 public String getCabstract() { 57 return cabstract; 58 } 59 public void setCabstract(String cabstract) { 60 this.cabstract = cabstract; 61 } 62 public String getEabstract() { 63 return eabstract; 64 } 65 public void setEabstract(String eabstract) { 66 this.eabstract = eabstract; 67 } 68 public String getCkey() { 69 return ckey; 70 } 71 public void setCkey(String ckey) { 72 this.ckey = ckey; 73 } 74 public String getEkey() { 75 return ekey; 76 } 77 public void setEkey(String ekey) { 78 this.ekey = ekey; 79 } 80 public String getContent() { 81 return content; 82 } 83 public void setContent(String content) { 84 this.content = content; 85 } 86 public String getReceiver() { 87 return receiver; 88 } 89 public void setReceiver(String receiver) { 90 this.receiver = receiver; 91 } 92 public String getStatus() { 93 return status; 94 } 95 public void setStatus(String status) { 96 this.status = status; 97 } 98 public String getName() { 99 return name; 100 } 101 public void setName(String name) { 102 this.name = name; 103 } 104 }
ContributeServlet.java(在servlet文件下建立此java文件)
1 package servlet; 2 3 import java.io.IOException; 4 import java.util.List; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 import javax.servlet.http.HttpSession; 12 import javax.swing.JOptionPane; 13 14 import dao.ContributeDao; 15 import util.Story; 16 17 /** 18 * Servlet implementation class ContributeServlet 19 */ 20 @WebServlet("/ContributeServlet") 21 public class ContributeServlet extends HttpServlet { 22 private static final long serialVersionUID = 1L; 23 24 /** 25 * @see HttpServlet#HttpServlet() 26 */ 27 public ContributeServlet() { 28 super(); 29 // TODO Auto-generated constructor stub 30 } 31 32 ContributeDao dao=new ContributeDao(); 33 34 /** 35 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 36 */ 37 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 38 // TODO Auto-generated method stub 39 //response.getWriter().append("Served at: ").append(request.getContextPath()); 40 doPost(request,response); 41 } 42 43 /** 44 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 45 */ 46 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 47 // TODO Auto-generated method stub 48 //doGet(request, response); 49 50 request.setCharacterEncoding("utf-8"); 51 response.setCharacterEncoding("utf-8"); 52 53 System.out.println("进入ContributeServlet"); 54 String method = request.getParameter("method"); 55 System.out.println(method); 56 if("submit".equals(method)) { 57 submit(request,response);//创建稿件 58 } 59 60 } 61 62 public void submit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 63 response.setCharacterEncoding("UTF-8"); 64 request.setCharacterEncoding("UTF-8"); 65 66 String ctitle = request.getParameter("ctitle"); 67 String etitle = request.getParameter("etitle"); 68 String cabstract = request.getParameter("cabstract"); 69 String eabstract = request.getParameter("eabstract"); 70 String ckey = request.getParameter("ckey"); 71 String ekey = request.getParameter("ekey"); 72 String content = request.getParameter("content"); 73 String name = request.getParameter("name"); 74 75 Story story=new Story(ctitle,etitle,cabstract,eabstract,ckey,ekey,content,"格式审查中","1",name); 76 77 if(dao.submit(story)) { 78 JOptionPane.showMessageDialog(null, "投稿成功", "success", JOptionPane.PLAIN_MESSAGE); 79 request.getRequestDispatcher("Contribute_submit.jsp").forward(request, response); 80 }else { 81 request.getRequestDispatcher("TestFail.jsp").forward(request, response); 82 } 83 84 } 85 86 }
ContributeDao.java(在dao文件下建立此java文件)
1 package dao; 2 3 import java.sql.Connection; 4 import java.sql.PreparedStatement; 5 import java.sql.ResultSet; 6 7 import databse.Database; 8 import util.Story; 9 10 public class ContributeDao { 11 /** 12 * 投稿 13 * 14 * @param story 15 * @return 16 */ 17 public boolean submit(Story story) { 18 Connection conn = null; 19 PreparedStatement pstm = null; 20 PreparedStatement pstm1 = null; 21 boolean judge = false; 22 try { 23 conn = Database.getConnection(); 24 String sql = "insert into story(ctitle,etitle,cabstract,eabstract,ckey,ekey,content,receiver,status,name) values(?,?,?,?,?,?,?,?,?,?)"; 25 System.out.println(sql); 26 pstm = conn.prepareStatement(sql); 27 28 pstm.setString(1, story.getCtitle()); 29 pstm.setString(2, story.getEtitle()); 30 pstm.setString(3, story.getCabstract()); 31 pstm.setString(4, story.getEabstract()); 32 pstm.setString(5, story.getCkey()); 33 pstm.setString(6, story.getEkey()); 34 pstm.setString(7, story.getContent()); 35 pstm.setString(8, story.getReceiver()); 36 pstm.setString(9, story.getStatus()); 37 pstm.setString(10, story.getName()); 38 39 String sql1 = "insert into storysituation(ctitle,receiver) values(?,?)"; 40 pstm1 = conn.prepareStatement(sql1); 41 pstm1.setString(1, story.getCtitle()); 42 pstm1.setString(2, story.getReceiver()); 43 44 // 执行插入操作 45 int num = pstm.executeUpdate(); 46 int num1 = pstm1.executeUpdate(); 47 if (num > 0 && num1 > 0) { 48 System.out.println("投稿成功"); 49 judge = true; 50 } else { 51 System.out.println("投稿失败"); 52 judge = false; 53 } 54 } catch (Exception e) { 55 e.printStackTrace(); 56 } finally { 57 // SQL执行完成后释放相关资源 58 Database.close(conn, pstm); 59 } 60 return judge; 61 } 62 }
TestFail.jsp
1 <%@ page language="java" contentType="text/html; charset=utf-8" 2 pageEncoding="utf-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="utf-8"> 7 <title>Test</title> 8 </head> 9 <body> 10 Fail 11 </body> 12 </html>
标签:投稿,String,request,story,我要,ctitle,import,public,审稿 来源: https://www.cnblogs.com/miao-com/p/15373374.html