基于struts2,hibernate的小javaweb项目

19:47:49

这是截图

闲话不说 就开始了

web-xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- structs2的配置 --><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>
</web-app>

 struts-xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><package name="default" extends="struts-default"><!-- 用于页面重转 --><action name="turnaddMessage" class="sedion.xq.action.turnAction"><result name="success">/WEB-INF/student/addMessage.jsp</result></action><action name="turndeleteMessage" class="sedion.xq.action.turnAction"method="getid"><result name="success">/WEB-INF/student/deleteMessage.jsp</result></action><action name="turnfindMessage" class="sedion.xq.action.turnAction"method="getid"><result name="success">/WEB-INF/student/findMessage.jsp</result></action><!-- look stu message --><action name="lookMessageAction" class="sedion.xq.action.lookMessageAction"><result name="success">/WEB-INF/student/lookMessage.jsp</result><result name="input">/index.jsp</result></action><!-- delet stu message --><action name="deleteMessageAction" class="sedion.xq.action.deleteMessageAction"><result name="success" type="chain">lookMessageAction</result><result name="input">/student/deleteMessage.jsp</result></action><!-- add stu message --><action name="addMessageActon" class="sedion.xq.action.addMessageAction"><result name="success" type="chain">lookMessageAction</result><result name="input">/student/deleteMessage.jsp</result></action><!-- find stu message --><action name="findMessageAction" class="sedion.xq.action.findMessageAction"><result name="success">/WEB-INF/student/updateMessage.jsp</result><result name="input">/student/findMessage.jsp</result></action><!-- update stu message --><action name="updateMessageActon" class="sedion.xq.action.updateMessageAction"><result name="success" type="chain">lookMessageAction</result><result name="input">/WEB-INF/student/updateMessage.jsp</result></action></package></struts>

 hibernate.cfg.xml:(申明 这里用的是SQL service 2005   若修改 这里修改 链接数据库    该数据库  名字LQQ  里面一张表格   在最后会发布)

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools.  -->
<hibernate-configuration><session-factory><property name="connection.username">sa</property><property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=LQQ</property><property name="dialect">org.hibernate.dialect.SQLServerDialect</property><!--<property name="myeclipse.connection.profile">LoginSystem</property>  --><property name="connection.password">sa</property><property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property><property name="show_sql">true</property><!-- POJO 类映射配置--><mapping resource="sedion/xq/ORM/Stuinfo.hbm.xml" /></session-factory>
</hibernate-configuration>

 然后 贴出  HibernateSessionFactory.java:

package sedion.xq.hibernate;import javax.swing.JOptionPane;import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;public class HibernateSessionFactory {private static SessionFactory sessionFactory;private static Configuration configuration = new Configuration();public HibernateSessionFactory() {}static {try {Configuration configure = configuration.configure("hibernate.cfg.xml");System.out.println(configure);sessionFactory = configure.buildSessionFactory();} catch (Exception e) {// TODO: handle exceptionSystem.out.println("HibernateSessionFactory  wrong!!");message("生成SessionFactory失败"+e);}}public static Session getSession() {System.out.println(sessionFactory.openSession());return sessionFactory.openSession();}public static void message(String mess){int type=JOptionPane.YES_NO_CANCEL_OPTION;String title="提示消息";JOptionPane.showMessageDialog(null,mess,title, type);}
}

 

然后 再贴出  ORM:

Stuinfo.java:

package sedion.xq.ORM;public class Stuinfo {private String id;private String name;private String sex;private int age;private float weight;public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public float getWeight() {return weight;}public void setWeight(float weight) {this.weight = weight;}}

 该类的映射文件如下:

Stuinfo.hbm.xml(自然可以根据这个表格  还原数据库的表格  表名:stuinfo):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0
//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping><class name="sedion.xq.ORM.Stuinfo" table="stuinfo"><id name="id" type="string"><column name="id" length="20" /><generator class="assigned" /></id><property name="name" type="string" length="20" /><property name="sex" type="string" length="5" /><property name="age" type="integer" /><property name="weight" type="float" /></class>
</hibernate-mapping>

 

然后 再贴出  DAO层:

StudentDao.java:

package sedion.xq.DAO;import java.util.List;import javax.swing.JOptionPane;import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;import sedion.xq.ORM.Stuinfo;
import sedion.xq.hibernate.HibernateSessionFactory;
import sun.swing.UIAction;public class StudentDao {private Transaction transaction;private Session session;private Query query;public StudentDao() {}// 显示public List findAllInfo() {session = HibernateSessionFactory.getSession();try {transaction = session.beginTransaction();String querysString = "from Stuinfo";query = session.createQuery(querysString);List<Stuinfo> list = query.list();System.out.println(list);transaction.commit();session.close();return list;} catch (Exception e) {message("findInfo.error" + e);e.printStackTrace();return null;}}// save messagepublic boolean saveInfo(Stuinfo info) {try {session = HibernateSessionFactory.getSession();transaction = session.beginTransaction();session.save(info);transaction.commit();session.close();return true;} catch (Exception e) {message("saveInfo.error" + e);e.printStackTrace();return false;}}public boolean deleteInfo(String id) {try {session = HibernateSessionFactory.getSession();transaction = session.beginTransaction();Stuinfo info = new Stuinfo();info = (Stuinfo) session.get(Stuinfo.class, id);session.delete(info);transaction.commit();session.close();return true;} catch (Exception e) {message("deleteInfo.error" + e);e.printStackTrace();return false;}}public List<Stuinfo> findInfo(String id) {try {session = HibernateSessionFactory.getSession();transaction = session.beginTransaction();query = session.createQuery("from Stuinfo stu where stu.id like?");query.setString(0, id);List<Stuinfo> list = query.list();System.out.println(list);transaction.commit();session.close();return list;} catch (Exception e) {message("deleteInfo.error" + e);e.printStackTrace();return null;}}public boolean updateInfo(Stuinfo info,String id) {try {System.out.println(id+"didiididid");session = HibernateSessionFactory.getSession();transaction = session.beginTransaction();query = session.createQuery("delete from Stuinfo stu where stu.id like?");query.setString(0, id);query.executeUpdate();session.saveOrUpdate(info);transaction.commit();session.close();return true;} catch (Exception e) {message("updateInfo.error" + e);e.printStackTrace();return false;}}private void message(String mess) {int type = JOptionPane.YES_NO_CANCEL_OPTION;String title = "提示消息";JOptionPane.showMessageDialog(null, mess, title, type);}}

 下面是6个 jsp:

index.JSP:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息管理</title></head><body><div align="center"><font size=6>学生信息管理系统Struts2+ Hibernate</font><hr color="red"/><font > ------made by sedion.xq</font><br /><s:a href="lookMessageAction.action">点击进入</s:a></div></body>
</html>

 

lookMessage.jsp:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息统一查询</title></head><body bgcolor="#7EC0EE"><s:div align="center"><hr color="red" /><br /><table align="center" width="80%"><tr><td width="25%">查看学生信息</td><td width="25%"><s:a href="turnaddMessage.action">添加学生信息</s:a></td><td width="25%"><s:a href="turnfindMessage.action">修改学生信息</s:a></td><td width="25%"><s:a href="turndeleteMessage.action">删除学生信息</s:a></td></tr></table><br /><hr color="red" /><br /><br /><br /><span>你要查询的数据表的人数共有 <%=request.getSession().getAttribute("count")%>人</span></s:div><table align="center" width="80%" border="2" bordercolor="blue"><tr><th>记录条数</th><th>学号</th><th>姓名</th><th>性别</th><th>年龄</th><th>体重</th></tr><s:iterator id="lsit" value="list" status="st"><tr><td align="center"><s:property value="#st.count" /></td><td>${id}</td><td>${name}</td><td>${sex}</td><td>${age}</td><td>${weight}</td></tr></s:iterator></table></body>
</html>

 updateMessage.jsp:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息--修改信息</title></head><body bgcolor="#7EC0EE"><s:div align="center"><hr color="red" /><br /><table align="center" width="80%"><tr><td width="25%"><s:a href="lookMessageAction.action">查看学生信息</s:a></td><td width="25%"><s:a href="turnaddMessage.action">添加学生信息</s:a></td><td width="25%"><s:a>修改学生信息</s:a></td><td width="25%"><s:a href="turndeleteMessage.action">删除学生信息</s:a></td></tr></table><br /><hr color="red" /><br /><br /><br /><center><font color="black" size="6">修改学生信息</font></center></s:div><s:form action="updateMessageActon" method="post"><table align="center" width="30%" border="2"><s:iterator value="list" id="list"><tr><td><s:textfield readonly="true" name="id" label="学号" maxLength="16" value="%{id}"></s:textfield></td><td><s:textfield name="name" label="姓名" value="%{name}"></s:textfield></td><td><s:select name="sex" label="性别" list="{'男','女'}" value="%{sex}" /></td><td><s:textfield name="age" label="年龄" value="%{age}"></s:textfield></td><td><s:textfield name="weight" label="体重" value="%{weight}"></s:textfield></td><td colspan="2"><s:submit value="提交" align="center"></s:submit><s:reset value="清除" align="center"></s:reset></td></tr></s:iterator></table></s:form><br></body>
</html>

 findMessage.jsp:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息管理系统-查找</title></head><body bgcolor="#7EC0EE"><s:div align="center"><hr color="red" /><br /><table align="center" width="80%"><tr><td width="25%"><a href="lookMessageAction.action">查看学生信息</a></td><td width="25%"><s:a href="turnaddMessage.action">添加学生信息</s:a></td><td width="25%"><s:a>修改学生信息</s:a></td><td width="25%"><s:a href="turndeleteMessage.action">删除学生信息</s:a></td></tr></table><br /><hr color="red" /><br /><br /><br /><font size="5">修改学生信息</font></s:div><s:form action="findMessageAction" method="post"><table align="center" width="40%" border="2" bordercolor="blue"><tr><td width="40%"><s:select name="id" label="请选择要修改的学生的学号:" list="list.{id}"></s:select></td><td><s:submit value="确定" align="center"></s:submit></td></tr></table></s:form></body>
</html>

 deleteMessage.jsp:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息--删除</title></head><body><body bgcolor="#7EC0EE"><s:div align="center"><hr color="red" /><br /><table align="center" width="80%"><tr><td width="25%"><s:a href="lookMessageAction.action">查看学生信息</s:a></td><td width="25%"><s:a href="turnaddMessage.action">添加学生信息</s:a></td><td width="25%"><s:a href="turnfindMessage.action">修改学生信息</s:a></td><td width="25%"><s:a>删除学生信息</s:a></td></tr></table><br /><hr color="red" /><br /><br /><br /><font size="5">删除学生信息</font></s:div><s:form action="deleteMessageAction" method="post"><table align="center" width="40%" border="2" bordercolor="blue"><tr><td width="40%"><s:select name="id" label="请选择要删除的学生的学号:" list="list.{id}"></s:select></td><td ><s:submit value="确定" align="center"></s:submit></td></tr></table></s:form></body>
</html>

 addMessage.jsp:

<%@	page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>学生信息--添加信息</title></head><body bgcolor="#7EC0EE"><s:div cssClass="align"><hr color="red" /><br /><table align="center" width="80%"><tr><td width="25%"><s:a href="lookMessageAction.action">查看学生信息</s:a></td><td width="25%">添加学生信息</td><td width="25%"><s:a href="turnfindMessage.action">修改学生信息</s:a></td><td width="25%"><s:a href="turndeleteMessage.action">删除学生信息</s:a></td></tr></table><br /><hr color="red" /><br /><br /><br /><center><font color="black" size="6">添加学生信息</font></center></s:div><s:form action="addMessageActon" method="post"><table align="center" width="30%"  border="2"><tr><td><s:textfield name="id" label="学号" maxLength="16"></s:textfield></td><td><s:textfield name="name" label="姓名" ></s:textfield></td><td><s:select name="sex" label="性别" list="{'男','女'}"/></td><td><s:textfield name="age" label="年龄"></s:textfield></td><td><s:textfield name="weight" label="体重" ></s:textfield></td><td colspan="2" ><s:submit value="提交" align="center"></s:submit><s:reset value="清除" align="center"></s:reset></td></tr></table></s:form></body>
</html>

 下面是6个action包里面的处理:

turnAction.java:

 

package sedion.xq.action;import java.util.ArrayList;
import java.util.List;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;import sedion.xq.DAO.StudentDao;
import sedion.xq.ORM.Stuinfo;public class turnAction extends ActionSupport {private List<Stuinfo> list = new ArrayList<Stuinfo>();public List<Stuinfo> getList() {return list;}public void setList(List<Stuinfo> list) {this.list = list;}public String execute() throws Exception {return "success";}public String getid() throws Exception {StudentDao dao = new StudentDao();list = dao.findAllInfo();return "success";}
}

 lookMessageAction.java:

package sedion.xq.action;import java.util.ArrayList;
import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;
import com.sun.org.apache.bcel.internal.generic.NEW;import sedion.xq.DAO.StudentDao;
import sedion.xq.ORM.Stuinfo;public class lookMessageAction extends ActionSupport{private HttpServletRequest request;private String message = "input";private List<Stuinfo> list=new ArrayList<Stuinfo>();public List<Stuinfo> getList() {return list;}public void setList(List<Stuinfo> list) {this.list = list;}@SuppressWarnings("unchecked")public String execute() throws Exception {try {		request = ServletActionContext.getRequest();StudentDao dao = new StudentDao();list = dao.findAllInfo();request.getSession().setAttribute("count", list.size());request.getSession().setAttribute("allInfo", list);message = "success";} catch (Exception e) {e.printStackTrace();}return message;}
}

 updateMessageAction:

package sedion.xq.action;import javax.swing.JOptionPane;import sedion.xq.DAO.StudentDao;
import sedion.xq.ORM.Stuinfo;import com.opensymphony.xwork2.ActionSupport;public class updateMessageAction extends ActionSupport {private String id;private String name;private String sex;private int age;private float weight;private String message = "input";public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public float getWeight() {return weight;}public void setWeight(float weight) {this.weight = weight;}private Stuinfo Info() {Stuinfo info = new Stuinfo();info.setId(this.getId());info.setName(this.getName());info.setSex(this.getSex());info.setAge(this.getAge());info.setWeight(this.getWeight());return info;}public String execute() throws Exception {StudentDao dao = new StudentDao();boolean update = dao.updateInfo(Info(),this.getId());if (update) {message = "success";}return message;}private void message(String mess) {int type = JOptionPane.YES_NO_CANCEL_OPTION;String title = "提示消息";JOptionPane.showMessageDialog(null, mess, title, type);}
}

 findMessageAction.java:

package sedion.xq.action;import java.util.ArrayList;
import java.util.List;import sedion.xq.DAO.StudentDao;
import sedion.xq.ORM.Stuinfo;import com.opensymphony.xwork2.ActionSupport;public class findMessageAction extends ActionSupport {private String id;private String message;private List<Stuinfo> list = new ArrayList<Stuinfo>();public List<Stuinfo> getList() {return list;}public void setList(List<Stuinfo> list) {this.list = list;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String execute() throws Exception {try {StudentDao dao = new StudentDao();list = dao.findInfo(this.getId());message = "success";} catch (Exception e) {e.printStackTrace();}return message;}}

 deleteMessageAction.java:

package sedion.xq.action;import org.apache.struts2.ServletActionContext;import sedion.xq.DAO.StudentDao;public class deleteMessageAction {private String id;private String message;public String getId() {return id;}public void setId(String id) {this.id = id;}public String execute() throws Exception {try {StudentDao dao = new StudentDao();boolean del=dao.deleteInfo(this.getId());if (del) {message = "success";}} catch (Exception e) {e.printStackTrace();}return message;}
}

 addMessageAction.java:

package sedion.xq.action;import java.util.List;import javax.swing.JOptionPane;import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.finder.ClassFinder.Info;import sedion.xq.DAO.StudentDao;
import sedion.xq.ORM.Stuinfo;public class addMessageAction extends ActionSupport{/*** */private static final long serialVersionUID = 1L;private String id;private String name;private String sex;private int age;private float weight;private String message = "input";public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public float getWeight() {return weight;}public void setWeight(float weight) {this.weight = weight;}public String execute() throws Exception {StudentDao dao = new StudentDao();boolean save = dao.saveInfo(Info());if (save) {message = "success";}return message;}private Stuinfo Info() {Stuinfo info = new Stuinfo();info.setId(this.getId());info.setName(this.getName());info.setSex(this.getSex());info.setAge(this.getAge());info.setWeight(this.getWeight());return info;}private void message(String mess) {int type = JOptionPane.YES_NO_CANCEL_OPTION;String title = "提示消息";JOptionPane.showMessageDialog(null, mess, title, type);}
}

 终于到最后了  , 下面发下  表格的截图

  

 

 谢谢  java大师我的偶像   一步一步接近

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/402684.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

YAML快速入门

From: https://www.jianshu.com/p/97222440cd08 我们学习Java&#xff0c;都是先介绍properties文件&#xff0c;使用properties文件配合Properties对象能够很方便的适用于应用配置上。然后在引入XML的时候&#xff0c;我们介绍properties格式在表现层级关系和结构关系的时候&…

MySql的用户权限

用户管理 MySQL数据库中的表与其他任何关系表没有区别&#xff0c;都可以通过典型的SQL命令修改其结构和数据。可以使用GRANT和REVOKE命令。通过这些命令&#xff0c;可以创建和禁用用户&#xff0c;可以在线授予和撤回用户访问权限。在5.0版本中增加了两个新命令&#xff1a;C…

.yaml 文件格式简介

From: https://www.cnblogs.com/wxmdevelop/p/7341292.html YAML 的意思其实是&#xff1a;"Yet Another Markup Language"&#xff08;仍是一种置标语言&#xff09;的缩写。 功能 YAML的语法和其他高阶语言类似&#xff0c;并且可以简单表达清单、散列表&#x…

jQuery与JS的区别,以及jQuery的基础语法

*在使用jQuery时&#xff0c;要在页面最上端加上 <script src"../jquery-1.11.2.min.js"></script> 看一下js与jQuery的区别&#xff1a; JS是这样使用的&#xff1a; <script type"text/javascript">根据ID取元素,取到的是具体的元素va…

sql语句中的时间查询

一般来说&#xff0c;我们在mysql数据库纪录数据时间时&#xff0c;都会选择datatime类型&#xff0c;这样时间可以精确到秒。但随之而来的一个问题是&#xff0c;当我们要取得某一段时间内的数据内容会有一些时间转换上的麻烦&#xff0c;例如我们要取得2002年3月2日到2003年7…

SnakeYaml快速入门

From: https://www.jianshu.com/p/d8136c913e52 在YAML快速入门[https://www.jianshu.com/p/97222440cd08]中&#xff0c;我们已经简单介绍了YAML的语法&#xff0c;本节中主要介绍YAML的配置读取。 目前有很多可以生成和解析YAML的第三方工具&#xff0c;常见的&#xff0c;…

CSS的一些零碎总结

1、CSS 伪元素用于向某些选择器设置特殊效果&#xff08;用来当作一个东西的&#xff0c;跟一个元素差不多&#xff0c;但不是元素&#xff09;。 ① :frist-line伪元素&#xff1a;用于向文本首行设置特殊样式&#xff0c;但是只能用于块级元素。 以下属性可应用于 “ frist-l…

有源代码的iphone项目

2019独角兽企业重金招聘Python工程师标准>>> http://blog.joomla.org.tw/iphone-ipad/104-iphone.html 學習和利用現成的資源是很重要的&#xff0c;以下列出有原始碼可下載的iPhone/iPod程式&#xff0c;這邊收集的是以已經放到App Store上的程式為主&#xff0c;…

匿名函数与闭包

<!DOCTYPE html><html lang"zh-CN"><head> <meta charset"UTF-8"> <title>闭包.html</title> <style> </style> <script src"jquery-1.7.2.min.js"></script> <script type&quo…

Content Security Policy 入门教程

From: http://www.ruanyifeng.com/blog/2016/09/csp.html 跨域脚本攻击 XSS 是最常见、危害最大的网页安全漏洞。 为了防止它们&#xff0c;要采取很多编程措施&#xff0c;非常麻烦。很多人提出&#xff0c;能不能根本上解决问题&#xff0c;浏览器自动禁止外部注入恶意脚本&…

windows编程基础

说明&#xff1a;只供学习交流&#xff0c;转载请注明出处 windows编程基础 &#xff08;1&#xff09;&#xff1a;API与SDK 我们在编写标准C程序的时候&#xff0c;经常会调用各种库函数来辅助完成某些功能&#xff1a;初学者使用得最多的库函数就是printf了&#xff0c;这些…

前端安全配置之Content-Security-Policy(csp)

From: https://www.cnblogs.com/heyuqing/p/6215761.html 什么是CSP CSP全称Content Security Policy ,可以直接翻译为内容安全策略,说白了,就是为了页面内容安全而制定的一系列防护策略. 通过CSP所约束的的规责指定可信的内容来源&#xff08;这里的内容可以指脚本、图片、i…

springboot跨域配置

From: https://www.cnblogs.com/nananana/p/8492185.html 前言&#xff1a; 当它请求的一个资源是从一个与它本身提供的第一个资源的不同的域名时&#xff0c;一个资源会发起一个跨域HTTP请求(Cross-site HTTP request)。 比如说&#xff0c;域名A ( http://domaina.example …

字符函数

getchar: 从stdio流中读字符 a getchar(); fputs:指定的文件写入一个字符串(不自动写入字符串结束标记符\0) fgets:从文件结构体指针stream中读取数据&#xff0c;每次读取一行。读取的数据保存在buf指向的字符数组中&#xff0c;每次最多读取 bufsize-1个字符…

SpringBoot配置Cors解决跨域请求问题

From: https://www.cnblogs.com/yuansc/p/9076604.html 一、同源策略简介 同源策略[same origin policy]是浏览器的一个安全功能&#xff0c;不同源的客户端脚本在没有明确授权的情况下&#xff0c;不能读写对方资源。 同源策略是浏览器安全的基石。 什么是源 源[origin]就…

Server Develop (三) 多进程实现C/S

多进程实现C/S 把上次的多进程简单的添加一个fork就可以实现一个简单的多进程服务器。具体进程创建和使用的函数&#xff0c;有时间得总结一下了&#xff5e;&#xff5e;&#xff5e;&#xff5e; if(fork()0){char buffer[1024];strcpy(buffer, "this is server! welcom…

l2正则化

在机器学习中&#xff0c;无论是分类还是回归&#xff0c;都可能存在由于特征过多而导致的过拟合问题。当然解决的办法有 &#xff08;1&#xff09;减少特征&#xff0c;留取最重要的特征。 &#xff08;2&#xff09;惩罚不重要的特征的权重。 但是通常情况下&#xff0c;我们…

机房收费系统的合作版

概述 机房收费系统的合作版自己负责的是B层和Facade层&#xff0c;在做这块的时候有很多的感触&#xff1a;动态SQL语句&#xff1b;设计模式&#xff1b;合作开发应该注意的点。其中动态SQL语句的理解已经在上一篇博客中写了&#xff0c;如果你有意向的话&#xff0c;可以看一…

ajax跨域,这应该是最全的解决方案了

From: https://segmentfault.com/a/1190000012469713 前言 从刚接触前端开发起&#xff0c;跨域这个词就一直以很高的频率在身边重复出现&#xff0c;一直到现在&#xff0c;已经调试过N个跨域相关的问题了&#xff0c;16年时也整理过一篇相关文章&#xff0c;但是感觉还是差…

centos 7.0防火墙导致vagrant端口映射失败

在vagrant上部署了centos7.0后&#xff0c;Vagrantfile端口转发设置后&#xff0c;宿主机访问客户机站点还是无法访问&#xff0c;问题出在:centos7.0以上版本默认会安装firewalld防火墙, firewalld有区(zone)概念,默认在public区,public:指定外部链接可以进入 先查看下当前端口…