前言:
从0到1的过程,记录一些学习中的知识点及问题。
开发工具
1、NetBeans
遇到的问题及解决方法分享
1.VS Code中点击Open With Live Server无反应
我遇到的情况是下载完插件后没有自动新建对应PATH路径
附上:详细解决方法
2.mysql workbench中Unable to connect to localhost
我遇到的情况是mysql服务一直没打开
附上:详细解决方法
JavaScript基础知识
主要为菜鸟教程中JavaScript教学实例学习
1.跳转网页链接
function jump(){
document.getElementById("myP").innerHTML="<a href='http://www.baidu.com'>baidu</a>";
}
疑问1:
如何实现点击按钮直接跳转
2.插入按钮的两种方法
<button onclick="myfunction()">alert</button>
<br>
<input type="button" onclick="myfunction()" value="alert1">
3.弹窗
警示框(内容换行)
function myfunction(){
alert("hello\nhow are you");
}
确认框
function myfun(){
var x;
var r=confirm("choose");
if (r==true){
x="you choose the \"confirm\"";
}
else{
x="you choose the \"cancel\"";
}
document.getElementById("demo").innerHTML=x;
}
对话框
function myword(){
var x;
var person=prompt("please enter your name","xiaoming");
if (person!==null && person!==""){
x="hollo"+person+",have a nice day!"
document.getElementById("pp").innerHTML=x;
}
}
4.闭包函数
var add = (function(){
var counter = 0;
return function(){
return counter +=1;
}
})();
function myfunction(){
document.getElementById("demo").innerHTML=add();
}
疑问2:
没有理解
5.标题格式中插入for循环
function myFunction(){
var x="",i;
for (i=1;i<=6;i++){
x=x+"<h"+i+">Heading"+i+"</h"+i+">";
}
document.getElementById("demo").innerHTML=x;
}
疑问3:
“”的顺序安排
知识点:循环
1.for
2.while
3.do while
4.break与continue
1.1 for in遍历数组内元素
function myFunction(){
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age:56};
for (x in person){
txt = txt + person[x];
}
document.getElementById("demo").innerHTML=txt;
}
6.onchange使用例子
<input type="text" id="fname" onchange="myFunction()">
<div>当你离开输入框后,小写字母自动转为大写字母</div>
<script>
function myFunction(){
var x=document.getElementById("fname");
x.value=x.value.toUpperCase();
}
</script>
7.错误处理
try 语句测试代码块的错误
catch 语句处理错误
throw 语句创建自定义错误
finally 语句在 try 和 catch 语句之后,无论是否有触发异常,该语句都会执行
function myFunction() {
var message, x;
message = document.getElementById("p01");
message.innerHTML = "";
x = document.getElementById("demo").value;
try {
if(x == "") throw "值是空的";
if(isNaN(x)) throw "值不是一个数字";
x = Number(x);
if(x > 10) throw "太大";
if(x < 5) throw "太小";
}
catch(err) {
message.innerHTML = "错误: " + err + ".";
}
finally {
document.getElementById("demo").value = "";
}
}
JSP基础知识
1.useBean的基础使用
<div style="text-align: center;">
<jsp:useBean id="obj" scope="session" class="ise.ShowTimeBean">
<jsp:setProperty name="obj" property="name" value="aaa"></jsp:setProperty>
</jsp:useBean>
<h3>时间(<span style="color: red;"><%= obj.getName() %></span>)111</h3>
<div style="color: red"><%= obj.getCurrentDateTime() %></div>
</div>
public class ShowTimeBean {
private String name;
private boolean valid;
private int count;
public ShowTimeBean(){
}
public String getCurrentDateTime(){
return new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public boolean isValid(){
return valid;
}
public void setValid(boolean valid){
this.valid = valid;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method")
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
2.forward
<jsp:forward page="index.html"></jsp:forward>
3.JSP页面被调用方式
1.url
2.getServletContext
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String type = request.getParameter("type");
if(type.equals("index")){
getServletContext().getRequestDispatcher("/index.html").forward(request, response);
}
else if(type.equals("date-time")){
getServletContext().getRequestDispatcher("/date-time.jsp").forward(request, response);
}
}
4.JSP、JSP+JavaBean、mvc
1.JSP
<div style="text-align: center;">
<p>只用JSP显示时间</p>
<% String str= new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());%>
<div style="color: red"><%= str%></div>
</div>
2.JSP+JavaBean
<div style="text-align: center;">
<h3>jsp+javaBean显示时间</h3>
<jsp:useBean id="obj" scope="session" class="ise.CreatTimeBean"/>
<div style="color: red"><jsp:getProperty name="obj" property="datetime"></jsp:getProperty> </div>
</div>
public class CreatTimeBean {
private String datetime;
public CreatTimeBean() {
}
public String getDatetime() {
this.datetime = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());
return datetime;
}
public void setDatetime(String date_time) {
this.datetime = date_time;
}
}
3.mvc
servlet调用javabean,再传给jsp
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CreatTimeBean obj = new CreatTimeBean();
String str = obj.getDatetime();
request.setAttribute("date-time-str",str);
getServletContext().getRequestDispatcher("/mvc.jsp").forward(request, response);
}
public class CreatTimeBean {
private String datetime;
public CreatTimeBean() {
}
public String getDatetime() {
this.datetime = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());
return datetime;
}
public void setDatetime(String date_time) {
this.datetime = date_time;
}
}
<body>
<div style="text-align: center;">
<h3>mvc显示时间</h3>
<div style="color: red"><%= request.getAttribute("date-time-str")%> </div>
</div>
</body>
JSTL标签语句
1.输出和循环
<span>字符串:</span>
<h4><c:out value="${str}" default="空对象"></c:out></h4>
<span>对象:</span>
<h4><c:out value="${student1.name}"/>,<c:out value="${student1.id}"/></h4>
<span>链表:</span>
<c:forEach var="s" items="${list}">
<h4><c:out value="${s.name}"/>,<c:out value="${s.id}"/></h4>
</c:forEach>
<c:out>只能输出setAttribute传输的
2.判断
<span>单分支:</span>
<h4>
<c:if test="${str eq 'hello'}">
输出hello
</c:if>
</h4>
<span>两个分支:</span>
<h4>
<c:choose>
<c:when test="${str == 'hello'}">
hello world
</c:when>
<c:otherwise>
nothing
</c:otherwise>
</c:choose>
</h4>
<span>多重分支:</span>
<h4>
<c:choose>
<c:when test="${str == '1'}">111</c:when>
<c:when test="${str == '2'}">222</c:when>
<c:when test="${str == '3'}">333</c:when>
<c:otherwise>other</c:otherwise>
</c:choose>
</h4>
3.c:set与c:remove
<span>设置变量</span>
<h4>
<c:set var="abc" value="111"></c:set>
<c:set var="abc" value="222"></c:set>
<c:remove var="abc"></c:remove>
<c:out value="${abc}" default="无此变量"></c:out>
<br>
<c:out value="${student1.name}" default="nothing"></c:out>
<br>
<c:set target="${student1}" property="name" value="老王"></c:set>
<c:out value="${student1.name}" default="nothing"></c:out>
</h4>
4.c:redirect与c:url
<c:url var="url1" value="date-time.jsp"></c:url>
<%--<c:redirect url="date-time.jsp"></c:redirect>--%>
<c:redirect url="${url1}"></c:redirect>
相当于forward
5.sql
6.fn
7.自定义标签
①设计 名称+动作
②编写tag类
③编写配置文件 xx.tld
④导入
public class HelloTag extends SimpleTagSupport {
private String str;
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
out.println("hello" + this.str);
}
public void setStr(String str) {
this.str = str;
}
}
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>my hello</short-name>
<tag>
<name>hello</name>
<tag-class>ise.HelloTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>str</name>
</attribute>
</tag>
</taglib>
<%@ taglib prefix="my" uri="WEB-INF/my.tld" %>