会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132460个问题
JAVA 全系列/(旧的隐藏)第十五阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 34396楼
Python 全系列/第五阶段:数据库编程/mysql的使用 34397楼

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script>
            function addPhotoNode(){
                //1.创建节点
                    //创建父节点p
                    var p = document.createElement("p");
                    //选择文件节点(选择照片)
                    var selectPhoto = document.createElement("input");
                    //删除本节点(新创建的节点)
                    var deletePhoto = document.createElement("button");
                //2.为创建的节点指定属性
                selectPhoto.type= "file";
                
                deletePhoto.innerText = "删除照片";
                //3.选择要添加到的位置
                    var destined = document.getElementById("destinedForm");
                //4.添加节点对象
                    p.innerHTML = "p标签里的内容";
                    //【1】将子节点添加到父节点
                    destined.appendChild(p);
                        p.appendChild(selectPhoto);
                        p.appendChild(deletePhoto);
                    //destined.appendChild(selectPhoto);
            }
        </script>
    </head>
    <body>
        <div>
            <form id = "destinedForm">
                <p>
                    用户名:<input id = "username" type = "text" placeholder = "邮箱/手机号"/>
                </p>
                <p>
                    照片:<input id = "photo" type = "file"/>&nbsp;
                    <button onclick = "addPhotoNode()">添加照片</button>
                </p>
                <p>
                    <input type = "submit"/>&nbsp;
                    <input type = "reset" value = "清空"/>
                </p>
            </form>

            
        </div>
    </body>
</html>


老师,我的点击添加 照片按钮之后,新添加出来的元素只能 维持0.5s然后网页就自动刷新,新添加的 元素也刷新没了,请问这是为什么?

JAVA 全系列/第四阶段:网页编程和设计/Javascript 语言(旧) 34399楼
JAVA 全系列/第一阶段:JAVA 快速入门/IDEA的使用和第一个java项目 34400楼
Python 全系列/第十五阶段:Python 爬虫开发/移动端爬虫开发- 34401楼
Python 全系列/第一阶段:Python入门/编程基本概念 34402楼

你好,老师,我是按照视频中的代码敲得,但是最后在浏览器没有显示登陆成功的字样

package com.hy.test;
/***
 * 在html中使用post方法,通过程序然后获取输入的信息,并且对web浏览器做出回应
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.ServerSocket;
import java.net.Socket;



public class Server3 {
	public static void main(String[] args) {
		String BLANK="\n";
		String CRLF="\r\n";//换行
		//1创建ServerSocket对象
		ServerSocket server=null;
		//2监听是否有客户端发来请求
		Socket client=null;
		//3创建Socket对象	
				//4创建输入流
		InputStream is=null;
		try {
			server = new ServerSocket(8080);	
			client = server.accept();
			is=client.getInputStream();
			byte[] buf=new byte[10240];
			int len=is.read(buf);
			System.out.println(new String(buf,0,len));
			/***
			 * 以下代码是对浏览器的请求做出响应
			 */
			StringBuilder sb=new StringBuilder();
			StringBuilder sbContent=new StringBuilder();//响应的文本
			sbContent.append("<html><head><title>响应结果</title></head>");
			sbContent.append("<body>登陆成功</body></html>");
			//1拼接像迎头
			sb.append("HTTP/1.1").append(BLANK).append(200).append(BLANK).append("ok");
			sb.append(CRLF);//换行
			sb.append("Content-Type: text/html;charset=utf-8");
			sb.append(CRLF);
			sb.append("Content-Length:").append(sbContent.toString().getBytes().length).append(CRLF);//换行,代表响应头和相应正文之间的空行
			sb.append(sbContent);
			
			//通过流输出
			BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(client.getOutputStream(),"utf-8"));
			bw.write(sb.toString());
			bw.flush();
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
		//关闭流
		try {
			IOClose.closeAll(is,client,server);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
	}

	private static InputStream InputStream(InputStream inputStream) {
		// TODO Auto-generated method stub
		return null;
	}
}

html代码

<html>
<head>
<title>我的第一个html</title>
</head>
<body>
<h1>hello world</h1>
<form action="http://localhost:8080/index.html" method="post">
<p>用户名:<input type="text" id="uname" name="username" /></p>
<p>密码:<input type="password" id="pwd" name="password" /></p>
<p><input type="submit" value="登陆"/></p>
</form>
</body>
</html>


image.png


 浏览器没有显示,但是eclipse控制台输出的正常的,所以想问一下是什么原因,感谢

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/手写服务器项目(旧) 34403楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 34404楼
JAVA 全系列/第四阶段:网页编程和设计/CSS3(旧) 34405楼
Python 全系列/第十二阶段:Python_Django3框架/Django初级 34407楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 34408楼
JAVA 全系列/(旧的隐藏)第十五阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 34409楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637