Tag Archives: html

[Solved] Android Error: AAPT: error: unescaped apostrophe in string;Multiple substitutions specified in non-positi

I. AAPT: error: unescaped apostrophe in string </ font>

Cause analysis of error reporting

When doing the internationalization multilingual function, I defined some strings in the arrays.xml file as follows

<item>My name's Lisa</item>

The error report is translated as the apostrophe
that is not replaced by the string. Therefore, I thought that the error report may be caused by ', so I replaced the above code with the following code to solve the error report.

<item>My name&quot;s Lisa</item>

Error reporting solution

apostrophe ' available & amp; quot; replacement, such as: <item> My name& quot; s Lisa you can use double quotation marks to enclose string resources, such as: <item>" My name's Lisa" escape characters can be used before apostrophe ', such as: <item> My name\'s Lisa

II. Multiple substitutions specified in non positive format

Cause analysis of error reporting

First, I defined some strings in the string. XML file

<string name = "upgrade_time"> Driver board: %s\t\t signal version.%s</string>

Error reporting translates to multiple substitutions specified in a non location format. The error reporting prompt mentions setting formatted = "false" , so I change the above code to the following one, so I won’t run error reporting.

<string name = "upgrade_time" formatted="false"> Driver board: %s\t\t signal version.%s</string>

Error resolution
After reviewing some blog posts and trying it out myself, there are these ways to fix the above error.
Add formatted="false" attribute in the string with %% to indicate a %
Third, some common HTML special character encoding
In the Android xml file, involving some special characters may be reported in the display of the error, you need to use HTML special characters to convert.

Special symbols HTML encoding
& &amp;
> &gt;
< &lt;
> &gt;
&quot;
> &gt;
Half a blank space ensp;
A blank space &emsp;
> &gt;

[Solved] Error:Plugin/Preset files are not allowed to export objects, only functions

There will be such an error when installing the on-demand loading of element UI under the official documentation of Vue.

Error:Plugin/Preset files are not allowed to export objects, only functions

In the official document of element

On demand import

With the help of   Babel plugin component, we can only introduce the required components to reduce the project volume.

First, install the Babel plugin component:

npm install babel-plugin-component -D

Then, change. Babelrc to:

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

At this time, after the installation and configuration are completed according to the official documents, an error will be reported when NPM run serve is started

Error: Cannot find module 'babel-preset-es2015'

This is due to the lack of Babel preset es2015 dependency

Just install the Babel preset es2015 dependency

npm i babel-preset-es2015 --save

This is OK, but sometimes you will still report an error when you start after installation

Error: Plugin/Preset files are not allowed to export objects, only functions.

I changed the preset in the babel.config.js file in the project     Not used in the official element UI documentation

Es2015, but change the content of babel.config.js to the following:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
    ["@babel/preset-env", {
      "useBuiltIns": "entry"
    }]
  ],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

Then install the dependencies on the command line

npm install --save-dev @babel/preset-env

This solves the error.

Duplicate keys detected: ‘***‘. This may cause an update error

Encountered while developing Vue project    Duplicate keys detected: ’13’. This may cause an update error. This error will not affect the page display, but will always be printed on the console. As shown in the figure  

 

Error reason: the key value set during V-for loop is not unique. As shown in the figure  

Solution

The key that sets the V-for loop is unique. As shown in the figure  

 

 

   

 

LSSchemaConfigureForStore failed with error Error Domain=NSOSStatusErrorDomain Code=-10817 “(null)“

LSSchemaConfigureForStore failed with error Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)" UserInfo={_LSFunction=_LSSchemaConfigureForStore, ExpectedSimulatorHash={length = 32, bytes = 0x15dde658 ed2a1267 ab2496d7 34f186ad ... ec431c65 02d68f35 }, _LSLine=409, WrongSimulatorHash={length = 32, bytes = 0xaf25dda9 e45baa35 610eaabd 5bc09901 ... 9cbe61f3 81d7b9d9 }}

  The solution is as follows:

Such a simple serialization system.text.json.serialization also reports an error?

Consulting area

kofifus:

I am going to switch json.net in the project to the native system. Text. JSON , but I encountered an unexpected error. The test code is as follows:


using System.Text.Json.Serialization;
using Newtonsoft.Json;

public class C {
  public C(string PracticeName) { this.PracticeName = PracticeName; }
  public string PracticeName;
}

var x = new C("1");
var json = JsonConvert.SerializeObject(x); // returns "{\"PracticeName\":\"1\"}"

var x1 = JsonConvert.DeserializeObject<C>(json); // correctly builds a C

var x2 = System.Text.Json.Serialization.JsonSerializer.Parse<C>(json);

The last line of the above code will report:


Exception thrown: 'System.NullReferenceException' in System.Text.Json.dll Object reference not set to an instance of an object.

What did I do wrong?

I found that this problem can be solved by parameterless constructor , but doing so will put the cart before the horse. Is there a flexible way to realize the simple functions that can be realized by JSON. Net .

Answer area

Christian Gollhardt:

In the . Net core 3.0 stage, the development of system. Text. JSON has not been completely completed. At present, only nonparametric constructor is supported, which may be supported in the future.

If you are migrating the old version to . Net core 3.0 , I still suggest you use newtonsoft. JSON .

    MVC

Install the microsoft.aspnetcore.mvc.newtonsoftjason package from nuget and inject it into the Services container.


services.AddMvc().AddNewtonsoftJson();

    SignalR:

InstallMicrosoft.AspNetCore.SignalR.Protocols.NewtonsoftJson package from Nuget


//Client
new HubConnectionBuilder()
.WithUrl("/chatHub")
.AddNewtonsoftJsonProtocol(...)
.Build();

//Server
services.AddSignalR().AddNewtonsoftJsonProtocol(...);

In this way, you can use json.net in . Net core 3.0 .

user11400447:

To solve this problem, you must make two changes:

praccename

    1. should be made into an attribute, not a field. Use a parameterless constructor

I wrote a console program, in which C1 is converted through newtonsoft. JSON , and C2 is converted through system. Text. JSON .


using Newtonsoft.Json;

namespace TestJsonParse
{
    class Program
    {
        static void Main(string[] args)
        {
            var c1 = new C1("1");
            var json1 = JsonConvert.SerializeObject(c1); // returns "{\"PracticeName\":\"1\"}"
            var x1 = JsonConvert.DeserializeObject<C1>(json1); // correctly builds a C1

            var c2 = new C2();
            string json2 = "{\"PracticeName\":\"1\"}";
            var x2 = System.Text.Json.Serialization.JsonSerializer.Parse<C2>(json2); // correctly builds a C2
        }

        class C1
        {
            public C1(string PracticeName) { this.PracticeName = PracticeName; }
            public string PracticeName;
        }

        class C2
        {
            public C2() { }
            public string PracticeName { get; set; }
        }
    }
}

Comment area

Times have changed. I’ve finished system.text.jason, and then I used the latest. Net 5 digression code.


namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var json = "{\"PracticeName\":\"1\"}";

            //json.net
            var x1 = JsonConvert.SerializeObject(json);

            //System.Text.Json
            var x2 = System.Text.Json.JsonSerializer.Deserialize<C>(json);

        }
    }

    public class C
    {
        public C(string PracticeName) { this.PracticeName = PracticeName; }
        public string PracticeName;
    }
}

The result is…. Continue to report errors…

What else can I say

The solution to the failure of HTML introducing external JS

Problem Description:

JavaScript files are imported from outside the script tag, but it does not work, and the JS code is invalid

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Login</title>
		<script src="js/main.js" type="text/javascript"></script>
	</head>
	
	<body>
		<form action="XXXXXX" method="post" name="login">
			Username: <input type="text" name="username" id="username" /> <br>
			Password: <input type="password" name="password" id="password" /> <br>
			<input type="submit" name="login" id="login" value="登录"/>
			<input type="button" name="logon" id="logon" value="注册" />
		</form>
	</body>
</html>

Cause analysis:

The execution order of HTML code is from top to bottom. The browser parses the HTML code from top to bottom. If JS is introduced into the head, the page tag may not be loaded during JS execution, resulting in the failure of JS to find the action object

Solution:

Just import an external JS file after the body

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Login</title>
	</head>
	
	<body>
		<form action="http://42.192.60.64:8080/user" method="post" name="login">
			Username: <input type="text" name="username" id="username" /> <br>
			Password: <input type="password" name="password" id="password" /> <br>
			<input type="submit" name="login" id="login" value="登录"/>
			<input type="button" name="logon" id="logon" value="注册" />
		</form>
	</body>
	
	<script src="js/main.js" type="text/javascript"></script>
</html>

Vue modifies the value passed by props error: Avoid mutating a prop directly since the value will be overwritten whenever the par

When doing a project, you will sometimes encounter this kind of error
this sentence means to avoid changing the prop directly, because as long as the parent component is re rendered, the value will be overridden. Instead, use data or calculate properties based on the prop value
you can’t directly change the props passed by the parent component, so what can you do?You can use emit to trigger the events of the parent component
parent component

<template>
    <div class="class">
        <Student :show="isShow" @hideStudent="hideStudent" />
        <button @click="showStudent">点我显示学生</button>
    </div>
</template>

<script>
import Student from "./student";
export default {
    name: "class",
    components: { Student },
    data() {
        return {
            isShow: false,
        };
    },

    methods: {
        showStudent() {
            this.isShow = true;
        },
        hideStudent() {
            this.isShow = false;
        },
    },
};
</script>

Subcomponents

<template>
    <div class="student" v-show="show">
        <nav>Mike</nav>
        <button @click="close">点我关闭student</button>
    </div>
</template>

<script>
export default {
    name: "student",
    props: {
        show: {
            type: Boolean,
            default:false
        },
    },
    methods: {
        close() {
            this.$emit("hideStudent");
        },
    },
};
</script>

Of course, subcomponents can also write like this, using watch to listen

<template>
    <div class="student" v-show="showStudent">
        <nav>Mike</nav>
        <button @click="close">点我关闭student</button>
    </div>
</template>

<script>
export default {
    name: "student",
    props: {
        show: {
            type: Boolean,
            default:false
        },
    },
    data() {
        return {
            showStudent:false
        };
    },
    watch:{
        show(){
            this.showStudent=this.show
        },
    },
    methods: {
        close() {
            this.$emit("hideStudent");
        },
    },
};
</script>

Finally, let’s take a look at the rendering


for more details about the value transmission of vueprops, see the value transmission of Vue parent-child components

After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:

**

After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:

**

Method 1: restart vscode, and then re-enter node — version (1) find the code.exe file
(2) right click the properties
(3) after opening the compatibility, select to run the program as an administrator and click OK
(4) in the last step, restart vscode and re-enter node — version

@requestbody: How to Use or Not Use

First of all, note that @ requestbody accepts the JSON string
so write this

dataType:"json",
contentType: 'application/json',
data: JSON.stringify(data.field),

Instead of @ requestbody, you can directly receive the JSON type

dataType:"json",
data: data.field,

The situation of not using @ requestbody
front end page

$.ajax({
		url: "http://localhost:8081/role//saveOrUpdate",
		method:"post",
	   dataType:"json",     
			// contentType: 'application/json',
		data: data.field,   
		success(data){
			console.log("======================")
				console.log(data.field)
			if(data.code == 200){
			layer.msg('add success', function () {
			 window.location = 'list.html';
				}); 
				}
		},
error(data){
	console.log(data)
	if(data.code != 200){
layer.msg(data); 
								}
								}
							});

Back end:

@PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(Roles roles){
        System.out.println(roles);
        boolean saveOrUpdate = roleService.saveOrUpdate(roles);
        if(saveOrUpdate == true)
            return Result.succ(null);
        else
            return Result.fail("failed to add");
    }

Using @ requestbody
front end:

$.ajax({
								url: "http://localhost:8081/role//saveOrUpdate",
								method:"post",
								dataType:"json",
								contentType: 'application/json',   
								data: JSON.stringify(data.field),  
								success(data){
									console.log("======================")
									console.log(data.field)
									if(data.code == 200){
										layer.msg('add success', function () {
										    window.location = 'list.html';
										}); 
									}
								},
								error(data){
									console.log(data)
									if(data.code != 200){
										layer.msg(data); 
								}
								}
							});

back-end

@PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Roles roles){
        System.out.println(roles);
        boolean saveOrUpdate = roleService.saveOrUpdate(roles);
        if(saveOrUpdate == true)
            return Result.succ(null);
        else
            return Result.fail("failed to add");
    }

Tomcat error: 500 The server encountered an internal error that prevented it from fulfilling this request

Background:
I use JDK1.8 and tomcat8.0, but I encounter the following two problems


then I made a new tomcat, and its version is as follows:

and it succeeded…..

The reason: Tomcat version is higher than JDK version

In addition, I have problems with my code
here is the error code:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="computer"%>
<html>
The three values entered a,b,c (representing the three sides of a triangle or the upper base, lower base and height of a trapezoid);
<body color=cyan>
        <form action="" method=get name=form> 
        <%--Get parameters to submit to yourself--%>
        <table>
        <tr><td>Enter value a: </td>
            <td><input type="text" name="a"></td>
        </tr>
        <tr><td>input value b: </td>
            <td><input type="text" name="b"></td>
        </tr>
        <tr><td>input value c: </td>
            <td><input type="text" name="c"></td>
        </tr>
        </table>
        <input type="radio" name="r" value="triangle">stands for triangle
        <input type="radio" name="r" value="lader">stands for trapezoid
        <br>
        <input type="submit" name="submit" value="submit" name=submit>stands for submit button
        </form>
        <% String a=request.getParameter("a");
           String b=request.getParameter("b");
           String c=request.getParameter("c");
           String cd=request.getParameter("r");
           if(a==null||b==null||c==null){
              a="0";
              b="0";
              c="0";
              cd="0";
                      
           }
           if(a.length()>0&&b.length()>0&&c.length()>0){
        %>
           <computer:Getarea numberA="<%=a%>" numberB="<%=b%>"
                             numberC="<%=c%>" condition="<%=cd%>"/>
           
           
           <br><%= message%>
           <br><%= area %>
        
        <% }
        %>
        </body>
        </html>


            
        

The reason for the error is that there are two more spaces. The error report is the same
here is the correct code:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="computer"%>
<html>
The three values entered a,b,c (representing the three sides of a triangle or the upper base, lower base and height of a trapezoid);
<body color=cyan>
        <form action="" method=get name=form> 
        <%--Get parameters to submit to yourself--%>
        <table>
        <tr><td>Enter value a: </td>
            <td><input type="text" name="a"></td>
        </tr>
        <tr><td>input value b: </td>
            <td><input type="text" name="b"></td>
        </tr>
        <tr><td>input value c: </td>
            <td><input type="text" name="c"></td>
        </tr>
        </table>
        <input type="radio" name="r" value="triangle">stands for triangle
        <input type="radio" name="r" value="lader">stands for trapezoid
        <br>
        <input type="submit" name="submit" value="submit" name=submit>stands for submit button
        </form>
        <% String a=request.getParameter("a");
           String b=request.getParameter("b");
           String c=request.getParameter("c");
           String cd=request.getParameter("r");
           if(a==null||b==null||c==null){
              a="0";
              b="0";
              c="0";
              cd="0";
                      
           }
           if(a.length()>0&&b.length()>0&&c.length()>0){
        %>
           <computer:Getarea numberA="<%=a%>" numberB="<%=b%>"
                             numberC="<%=c%>" condition="<%=cd%>"/>
           
           
           <br><%=message%>
           <br><%=area %>
        
        <% }
        %>
        </body>
        </html> 

[HTML] Python extracts HTML text to TXT

Regular debarking method

# -*- coding: utf-8 -*-
import re

def html_tag_rm(content: str):
	dr = re.compile(r'<[^>]+>',re.S)
	return dr.sub('',content)

nltk

It’s cumbersome
needs to install nltk, numpy, pyyaml

# -*- coding: utf-8 -*-
import nltk


def html_tag_rm(content: str):
	return nltk.clean_html(content)

htmlParser

import re
from sys import stderr 
from traceback import print_exc
from HTMLParser import HTMLParser

 
class _DeHTMLParser(HTMLParser): 
    def __init__(self): 
        HTMLParser.__init__(self) 
        self.__text = [] 
 
    def handle_data(self, data): 
        text = data.strip() 
        if len(text) > 0: 
            text = re.sub('[ \t\r\n]+', ' ', text) 
            self.__text.append(text + ' ') 
 
    def handle_starttag(self, tag, attrs): 
        if tag == 'p': 
            self.__text.append('\n\n') 
        elif tag == 'br': 
            self.__text.append('\n') 
 
    def handle_startendtag(self, tag, attrs): 
        if tag == 'br': 
            self.__text.append('\n\n') 
 
    def text(self): 
        return ''.join(self.__text).strip() 
 
 
def dehtml(text): 
    try: 
        parser = _DeHTMLParser() 
        parser.feed(text) 
        parser.close() 
        return parser.text() 
    except: 
        print_exc(file=stderr) 
        return text 
 
 
def main(): 
    text = r'''''
        <html>
            <body>
                <b>Project:</b> DeHTML<br>
                <b>Description</b>:<br>
                This small script is intended to allow conversion from HTML markup to 
                plain text.
            </body>
        </html>
    ''' 
    print(dehtml(text)) 
 
 
if __name__ == '__main__': 
    main()