Tag Archives: ssh

Linux apt-get update Error: Error in `appstreamcli‘: double free or corruption … Aborted (core dumped)

Reason:
the built-in libappstream of Ubuntu 16.0.4 is a version before 2.0. We must update it to a version above 3.0

Solution:

Clear libappstream3 (purge cleans more configuration files than remove)

sudo apt-get purge libappstream3

Operation results:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gnome-software-common libgtkspell3-3-0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  appstream* gnome-software* libappstream3* ubuntu-software*
0 upgraded, 0 newly installed, 4 to remove and 281 not upgraded.
After this operation, 1,759 kB disk space will be freed.
Do you want to continue?[Y/n] y
(Reading database ... 214637 files and directories currently installed.)
Removing ubuntu-software (3.20.1+git20160420.1.ca63436.ubuntu-xenial-0ubuntu2) ...
Removing gnome-software (3.20.1+git20160420.1.ca63436.ubuntu-xenial-0ubuntu2) ...
Purging configuration files for gnome-software (3.20.1+git20160420.1.ca63436.ubuntu-xenial-0ubuntu2) ...
Removing appstream (0.9.4-1) ...
Purging configuration files for appstream (0.9.4-1) ...
rmdir: failed to remove '/var/cache/app-info/': Directory not empty
Removing libappstream3:amd64 (0.9.4-1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for libglib2.0-0:amd64 (2.48.2-0ubuntu4.8) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160415-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu11.3) ...
yg@ubuntu:~$ 

Continue:

sudo apt autoremove

result:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  gnome-software-common libgtkspell3-3-0
0 upgraded, 0 newly installed, 2 to remove and 280 not upgraded.
After this operation, 2,744 kB disk space will be freed.
Do you want to continue?[Y/n] y
(Reading database ... 214577 files and directories currently installed.)
Removing gnome-software-common (3.20.1+git20160420.1.ca63436.ubuntu-xenial-0ubuntu2) ...
Removing libgtkspell3-3-0:amd64 (3.0.7-2) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu11.3) ...

Execution:

sudo apt-get update

result:

yg@ubuntu:~$ sudo apt-get update
Hit:1 http://archive.canonical.com/ubuntu xenial InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu xenial InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease                  
Hit:4 http://mirrors.aliyun.com/ubuntu xenial-backports InRelease                
Hit:5 http://mirrors.aliyun.com/ubuntu xenial-security InRelease                 
Reading package lists... Done                     
W: Target Sources (restricted/source/Sources) is configured multiple times in /etc/apt/sources.list:2 and /etc/apt/sources.list:4
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (multiverse/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (multiverse/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Sources (restricted/source/Sources) is configured multiple times in /etc/apt/sources.list:2 and /etc/apt/sources.list:4
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:3 and /etc/apt/sources.list:24
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:5 and /etc/apt/sources.list:29
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (multiverse/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (multiverse/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Translations (multiverse/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:11 and /etc/apt/sources.list:53
W: Target Packages (restricted/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Packages (restricted/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Packages (restricted/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Translations (restricted/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
W: Target Translations (restricted/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:15 and /etc/apt/sources.list:63
yg@ubuntu:~$ 

No more mistakes

Enter passphrase for key ‘/c/Users/**/.ssh/id_rsa‘ [How to Solve]

Create SSH key first

ssh-keygen -t rsa -C "[email protected]"

When generating SSH keys, if you accidentally set the passphrase, you will be prompted Enter passphrase for key '/ C/users/gf115 /. SSH/ID every time git pull and git push are used to clone remote warehouses_ RSA ', you need to manually enter the password every time to continue the operation. You can enter SSH keygen - P on the command line to reset it. Enter directly. If it is blank, there will be no password


then add the public key in Git
here are the specific steps:

insert the ID in. SSH in drive C_ Ras.pub file can be copied to git public key

test it and find that you can clone files in a remote warehouse directly without a password

[Solved] SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

root@node145:~# ssh-copy-id -i ~/.ssh/id_rsa.pub  [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
​
/usr/bin/ssh-copy-id: ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
ERROR: Someone could be eavesdropping on you right now (man-in-the-middle attack)!
ERROR: It is also possible that a host key has just been changed.
ERROR: The fingerprint for the ECDSA key sent by the remote host is
ERROR: SHA256:PO6FFmEQ9kOL1nodp3vLqVvCRW00Rhnn6cD9+SxbfbU.
ERROR: Please contact your system administrator.
ERROR: Add correct host key in /root/.ssh/known_hosts to get rid of this message.
ERROR: Offending ECDSA key in /root/.ssh/known_hosts:2
ERROR:   remove with:
ERROR:   ssh-keygen -f "/root/.ssh/known_hosts" -R "10.17.20.144"
ERROR: ECDSA host key for 10.17.20.144 has changed and you have requested strict checking.
ERROR: Host key verification failed.
​
### Solution Reassign the name of the file where the key is saved
root@node145:~# ssh-keygen -f "/root/.ssh/known_hosts" -R 10.17.20.144
# Host 10.17.20.144 found: line 2
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
root@node145:~# ssh-copy-id -i ~/.ssh/id_rsa.pub  [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.17.20.144 (10.17.20.144)' can't be established.
ECDSA key fingerprint is SHA256:PO6FFmEQ9kOL1nodp3vLqVvCRW00Rhnn6cD9+SxbfbU.
Are you sure you want to continue connecting (yes/no)?yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 
​
Number of key(s) added: 1
​
Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

SSH keygen command is used to generate, manage and transform authentication key for SSH. It supports RSA and DSA

SSH keygen (option)

-b: specify the length of the key. 
-e : read the private or public key file of openssh. 
-C: add comment. 
-f: specify the name of the file used to save the key. 
-i : reads the unencrypted ssh-v2 compatible private/public key file and then displays the openssh compatible private/public key on the standard output device. 
-l: display the fingerprint data of the public key file. 
-N: provide a new cipher. 
-P: provide the (old) cipher.
-q: silent mode. 
-t: specify the type of key to be created.

Xshell frequently disconnects, indicating socket error event: 32 error: 10053 connection failure

The SSH connection of xshell frequently prompts socket error event: 32 error: 10053

1. Cancel the check at the tunnel

2 modify/etc/SSH/sshd_ Configuration file under config

Change the value of clientaliveinterval to 60

Then restart the ssh server

At present, there is no frequent SSH disconnection problem, which should be effective

Windows subsystem Ubuntu 18.04 solves SSH problem

Download 18.04 of Ubuntu in the Microsoft Store of windows, but there are some problems in SSH localhost. Refer to some information on the Internet and make the following summary

    first, you need to install sshd sudo apt get install openssh server and then modify/etc/SSH/sshd_ Two items under config file

      permitrootlogin yes permitrootlogin changed to yes passwordauthentication yes passwordauthentication changed to yes Restart SSH service /etc/init.d/ssh restart execute SSH localhost again input password should be able to SSH successfully

[Solved] Linux error: SSH_exchange_identification: read: Connection reset by peer

Linux error SSH_exchange_identification: read: Connection reset by peer

Problem Description:

ssh_ exchange_ identification: read: Connection reset by peer

 

Cause of the problem:

check whether SSH connection restriction is enabled
VIM/etc/hosts. Allow
VIM/etc/hosts. Deny

 

resolvent:

if SSH connection restriction is enabled, add the IP of the source address to hosts.allow
effective in real time, no need to restart the service

Make the root user login through SSH and report the error of “permission denied, please try again”

When using SSH to log in to the ECS instance of the Linux system, if the root user enters the correct password, the following error message will appear.

Note: the non root user can log in normally, and the root user can log in normally through the management terminal.

Permission denied, please try again.

Please check the security log. If it contains the following error message, the problem is usually caused by the SELinux service enabled. Please refer to the solution to the problem caused by SELinux service. In other cases, please refer to the solution to the problem caused by forbidding the root user to log in.

error: Could not get shadow infromation for root.

 
Solutions to problems caused by forbidding root user to log in

Tips:

The related Linux configuration and instructions in this paper have been tested in CentOS 6.5 64 bit operating system. The operating system configuration of other types and versions may be different. Please refer to the official documents of the corresponding release for details. Related policies can improve the security of the server. Users are requested to decide whether to modify the relevant configuration based on the trade-off between security and ease of use.

Please refer to the following steps to check the configuration and modify it.

    log in to the ECS instance of Linux system through the management terminal

      View /etc/SSH/sshd through cat and other commands_ Whether the config configuration file contains a configuration similar to the following.

      PermitRootLogin no

      Note: the description of this parameter is as follows.

      If the parameter is not configured (by default), or the parameter value is configured to “yes”, the root user is allowed to log in. Only when the parameter value is set to “no”, will the root user be forbidden to log in.

      This parameter only affects the root user’s SSH login, and does not affect the root user’s login to the system through the management terminal and other ways.

      use VI and other editors to set the parameter value to “yes”, or delete the parameter, or comment (add “#” at the beginning) the whole line configuration. For example: ?Permitrootlogin yes .

      Note: it is recommended to back up the configuration file before modification.

      execute the following command to restart the SSH service.

      service sshd restart

      Try logging in to the server again using root. If the problem still exists, you can refer to the troubleshooting guide for remote login failure of ECS Linux SSH for further troubleshooting and analysis

       
      Solutions to problems caused by SELinux service

      You can choose to temporarily or permanently shut down SELinux service to solve the problem of SSH connection exception according to the needs of the on-site environment.

       
      Check SELinux service status

        log in to the Linux instance through the management terminal and execute the following command to view the current SELinux service status.

        /usr/sbin/sestatus -v 

        The system display is similar to the following.

        SELinux status:       enabled

        Tip: if

        The SELinux status parameter is

        enabled means that it is in the on state

        disabled is off.

       
      Temporarily shut down SELinux service

      Log in to the Linux instance and execute the following command to temporarily close SELinux.

      Tip: temporary modification of SELinux service status is real-time and effective, and there is no need to restart the system or instance.

      setenforce 0

       
      Permanently shut down SELinux service

      Log in to the Linux instance and execute the following command to shut down the SELinux service permanently.

      Tip: to permanently modify SELinux service status, you need to restart the system or instance before it can take effect.

      sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

      Tip: this command is only applicable when the SELinux service is in enforcing state.

Using jgit to report errors: the solution of algorithm negotiation failure

In today’s Java project, when using the jgit library to pull the remote code with SSH protocol, we encountered a lot of errors and stepped on a lot of holes to solve the problem. I’d like to record it here to help you
first of all, let’s talk about the use environment:

    1. there is no problem for the code to run on the Linux server. You can use SSH to pull the code. The local MacBook can pull code with SSH, but not with java code

Problem solving

        1. code error:

      com.jcraft.jsch.jschexception: algorithm negotiation failure

      1. this means that the algorithm negotiation fails, and SSH communication protocol has a stage of secret agreement and algorithm negotiation, in which both parties negotiate the final algorithm according to the algorithm supported by the local end and the opposite end. Different versions of openssh have different default algorithm lists, which may lead to the failure of algorithm negotiation. Use SSH – version to view the current openssh version
$ ssh -Version
OpenSSH_7.9p1, LibreSSL 2.7.3

View_ Protocol used in RSA private key file header

-----BEGIN OPENSSH PRIVATE KEY-----

Use SSH keygen - M PEM - t RSA to generate old format keys

-----BEGIN RSA PRIVATE KEY-----

When configuring the newly generated public key of SSH in gitlab repository settings in Git clone repository, specify the SSH private key file

private String private_key = "/Users/wang/.ssh/y";
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
            @Override
            protected void configure(OpenSshConfig.Host host, Session session) {
                session.setConfig("StrictHostKeyChecking", "no");
            }

            @Override
            protected JSch createDefaultJSch(FS fs) throws JSchException {
                JSch sch = super.createDefaultJSch(fs);
                sch.addIdentity(private_key); 
                return sch;
            }
        };

        Git git = Git.cloneRepository()
                .setURI(gitUrl)
                .setTransportConfigCallback(transport -> {
                    SshTransport sshTransport = (SshTransport) transport;
                    sshTransport.setSshSessionFactory(sshSessionFactory);
                })
                .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password))
                .setDirectory(new File(codePath))
                .setBranch(commitId)
                .call();
        checkoutBranch(git, commitId);
        return git;

Other issues

      1. an error is reported when jsch connects to SSH: the invalid private key reports an error in the private key file that uses

--- begin open private key -----

      1. protocol by default. Just use the above method to generate the old RSA private key. In

/etc/SSH/sshd_ Add the following two lines to the config

      1. file to enable SSH to support corresponding algorithms and Macs
KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

MACs [email protected],[email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,[email protected],hmac-md5,hmac-sha1,hmac-sha1-96,hmac-md5-96

Restart sshd service on MAC

sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Stop sshd service on MAC

sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist

How to check whether a process is started

sudo launchctl list | grep sshd
0   com.openssh.sshd

Can’t connect to MySQL server on ‘192.168.64.132‘

Sqlog failed to connect to MySQL database in Linux system
error message: can’t connect to MySQL server on ‘192.168.64.132’

It can be connected before, but it is not enough to install the virtual machine image. According to the data, you can use SSH connection, and the configuration is as follows:

If you don’t use SSH connection, you need to use win’s telnet to test whether telnet 192.168.64.132 3306 and telnet 192.168.64.132 22 can connect 1, the virtual machine does not set IPv4 forwarding,
2, the virtual machine opens the firewall and does not expose port 3306( 22 can be connected, 3306 can not be connected).

Reference blog

Using common file upload to upload files in SSH project

Today, the project used to upload. What I store in my database is the URL of the file, so I have to do some processing in the background. I have written several times before uploading, and I feel that the amount of code is too large. Today, I searched the Internet, and it will be much easier to upload with common file upload. After groping for an afternoon, I finally got it done. The background code is as follows

//The uploaded file
private File upload;
//file name and type
private String uploadContentType;
private String uploadFileName;
/*This is the variable to be written in the action, you must write it, otherwise it will be very troublesome, Struts2 will automatically assign the file to be uploaded, the file name, type, etc.*/

/// The following is the processing method
public String uploadStaffImage() throws Exception{
	//Take the file name and path, rename the file name with uuid to prevent Chinese mess
	String fileName = UUID.randomUUID().toString();
        //intercept file type
        String fileType = this.uploadFileName.substring(this.uploadFileName.lastIndexOf("."), this.uploadFileName.length());
        //New file name
        String file = fileName + fileType;
        // My directory is under "StaffImg" folder
        String path = request.getSession().getServletContext().getRealPath("/StaffImg");
	InputStream is = new FileInputStream(getUpload());  
        //Create an output stream to generate a new file  
        OutputStream os = new FileOutputStream(path + "//" + file);  
        //write disk 
        IOUtils.copy(is, os);
        os.flush();  
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
        //Update the URL in the database
        String imgURL = "StaffImg/"+file;
        this.staffFileUpLoadService.updataStaffImgURL(this.staffId, imgURL);
	return SUCCESS;
}

A total of 13 lines of code, compared to the previous written to be a lot more concise, method use is relatively simple.

This method can only upload a single file. If you upload in batches, the idea is the same, and you should add a loop in the outer layer
instead

ognl.MethodFailedException: Method “setId” failed for object Itemer/org.springframework.orm.hibernat

Error in importing data from SSH framework of Java project:

19:17:12,518  WARN OgnlValueStack:64 - Error setting expression 'iid' with value '[Ljava.lang.String;@52b1eaed'
ognl.MethodFailedException: Method "setIid" failed for object Itemer [iid=0, iname=null, imanager=null, imember=null, id=1, cid=6] [java.lang.NoSuchMethodException: cn.zx.ghjmaven.domain.Itemer.setIid([Ljava.lang.String;)]
	at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1305)
	at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1494)
	at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
	at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
	at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
	at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
	at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:78)
	at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
	at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
	at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
	at ognl.SimpleNode.setValue(SimpleNode.java:301)
	at ognl.Ognl.setValue(Ognl.java:737)
	at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: cn.zx.ghjmaven.domain.Itemer.setIid([Ljava.lang.String;)
	at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1246)
	... 67 more
/-- Encapsulated exception ------------\
java.lang.NoSuchMethodException: cn.zx.ghjmaven.domain.Itemer.setIid([Ljava.lang.String;)
	at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1246)
	at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1494)
	at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
	at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
	at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
	at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
	at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:78)
	at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2332)
	at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
	at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
	at ognl.SimpleNode.setValue(SimpleNode.java:301)
	at ognl.Ognl.setValue(Ognl.java:737)
	at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
	at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563)
	at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
\--------------------------------------/

Error correction results:

In fact, I saw this mistake from the beginning, but I can’t understand why it was wrong. Let’s talk about my file configuration. First, upload is a file type file. Second, this function is to upload photos. Then I found the first error. The ectype of the form element in the JSP I want to upload is not set to enctype = “multipart/form data”. The second error is that many people did not pay attention to it completely, that is, our form submission method should be method = “post”. And the key is this method.

analysis:

Enctype = “multipart/form data” indicates that the content submitted by the file is binary, which can handle photos well. Moreover, the get method must be attached to the link to submit, so all submitted methods are Stirng. So you should choose to use post. But it should also be noted that the use of post transmission is more secure and efficient.

——Solutions——————–

without a form set to enctype ‘multipart/form-data’.

To set the enctype of the form.  

<form id=”addItemerForm” action=”${ pageContext.request.contextPath }/bc/itemerAction_ save” method=”post” enctype=”multipart/form-data”>

The above is the method I found in Baidu search, but I didn’t upload the file, so I was very depressed. After reading the first line, I thought it must have something to do with ID, and then I tested it org.springframework.orm . hibernate3. Hibernatesystemexception error,

The reason for this error may be that the database primary key is self incrementing, but the background entity class primary key is not self incrementing. I just annotate the entity class ID with @ generatedvalue (strategy = identity)

Java project cannot import entity class package and service package, controller layer reports error, fix project setup is OK

Frame SSH

The previous packages are all OK. I create a management class of the service layer. When I add a new service, it appears:

Java project cannot import entity class package and service package, controller layer reports an error,

At the beginning, I thought that the package was wrong. I deleted the package in the controller layer and imported it again, but it still couldn’t work,

Check the cause of the error and find out

Then select fix project setup and it will be OK.

Record down, in Baidu did not find the answer, follow-up continuous attention, have to know the reason can leave a message, thank you~~