gs-handling-form-submission | Handling Form Submission : : Learn how to create and submit | Model View Controller library
kandi X-RAY | gs-handling-form-submission Summary
Support
Quality
Security
License
Reuse
- Gets the greeting form
- Registers a new greeting .
- Entry point for the main application .
- Gets the id .
- Set the id .
- Gets the text content .
- Sets the content of the embed .
gs-handling-form-submission Key Features
gs-handling-form-submission Examples and Code Snippets
Trending Discussions on gs-handling-form-submission
Trending Discussions on gs-handling-form-submission
QUESTION
what is expected
docker should build the image and run the container out of it
Dockerfile
FROM centos:7
ENV JAVA_VERSION 8u191
ENV BUILD_VERSION b12
RUN yum -y install wget; wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/2787e4a523244c269598db4e85c51e0c/jdk-$JAVA_VERSION-linux-x64.rpm" -O /tmp/jdk-8-linux-x64.rpm; yum -y install /tmp/jdk-8-linux-x64.rpm
# JDK stripping
RUN rm -f /usr/java/jdk1.8.0_77/src.zip /usr/java/jdk1.8.0_77/javafx-src.zip
RUN rm -rf /usr/java/jdk1.8.0_77/lib/missioncontrol/ /usr/java/jdk1.8.0_77/lib/visualvm/ /usr/java/jdk1.8.0_77/db/
RUN alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
RUN alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 1
ENV JAVA_HOME /usr/java/latest
ENV PATH=$PATH:/usr/java/latest/bin/java
RUN echo "$PATH"
RUN rm -f /tmp/jdk-8-linux-x64.rpm; yum -y remove wget; yum -y clean all
COPY target/gs-handling-form-submission-0.1.0.jar /tmp/gs-handling-form-submission-0.1.0.jar
CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]
build-context is the current directory where Dockerfile resides. following is the directory structure
total 8
-rw-r--r--. 1 root root 1079 Oct 29 03:42 Dockerfile
-rw-rw-r--. 1 ec2-user ec2-user 1917 Oct 27 09:17 pom.xml
drwxrwxr-x. 4 ec2-user ec2-user 30 Oct 27 10:15 src
drwxr-xr-x. 9 root root 261 Oct 27 10:19 target
i am executing following command to build the image :
docker build --no-cache -f Dockerfile -t cpa:latest .
but when running the container , getting following message
docker run -d -p 8081:8081/tcp cpa
b2ba9831f1b74c73669843658727ca0d64fcd9de915739b96e17dcfd6e63c7db
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"java -jar /tmp/gs-handling-form-submission-0.1.0.jar\": stat java -jar /tmp/gs-handling-form-submission-0.1.0.jar: no such file or directory": unknown.
I am not sure why the built jar is not available in the /tmp dir of the container file system in the docker documentation COPY
is the right keyword to be used to copy files from host machine to container file system ... but then where is the issue ..? please suggest
EDIT 1 : fixed the type mistake from 77 to 191 here is the latest Dockerfile....
FROM centos:7
ENV JAVA_VERSION 8u191
ENV BUILD_VERSION b12
RUN yum -y install wget; wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/$JAVA_VERSION-$BUILD_VERSION/2787e4a523244c269598db4e85c51e0c/jdk-$JAVA_VERSION-linux-x64.rpm" -O /tmp/jdk-8-linux-x64.rpm; yum -y install /tmp/jdk-8-linux-x64.rpm
# JDK stripping
RUN rm -f /usr/java/jdk1.8.0_191/src.zip /usr/java/jdk1.8.0_191/javafx-src.zip
RUN rm -rf /usr/java/jdk1.8.0_191/lib/missioncontrol/ /usr/java/jdk1.8.0_191/lib/visualvm/ /usr/java/jdk1.8.0_191/db/
RUN alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
RUN alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 1
ENV JAVA_HOME /usr/java/latest
ENV PATH=$PATH:/usr/java/latest/bin/java
RUN echo "$PATH"
RUN rm -f /tmp/jdk-8-linux-x64.rpm; yum -y remove wget; yum -y clean all
COPY target/gs-handling-form-submission-0.1.0.jar /tmp/gs-handling-form-submission-0.1.0.jar
CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]
further, the target
dir is part of the build context please refer below:
[root@ip-172-31-14-242 cpa_final]# pwd
/tmp/cpa_final
[root@ip-172-31-14-242 cpa_final]# ll
total 8
-rw-r--r--. 1 root root 1084 Oct 29 05:16 Dockerfile
-rw-rw-r--. 1 ec2-user ec2-user 1917 Oct 27 09:17 pom.xml
drwxrwxr-x. 4 ec2-user ec2-user 30 Oct 27 10:15 src
drwxr-xr-x. 9 root root 261 Oct 27 10:19 target
[root@ip-172-31-14-242 cpa_final]# cd target/
[root@ip-172-31-14-242 target]# ll
total 17304
drwxr-xr-x. 4 root root 36 Oct 27 10:18 classes
drwxr-xr-x. 3 root root 25 Oct 27 10:18 generated-sources
drwxr-xr-x. 3 root root 30 Oct 27 10:18 generated-test-sources
-rw-r--r--. 1 root root 17708542 Oct 27 10:19 gs-handling-form-submission-0.1.0.jar
-rw-r--r--. 1 root root 4858 Oct 27 10:18 gs-handling-form-submission-0.1.0.jar.original
drwxr-xr-x. 2 root root 28 Oct 27 10:18 maven-archiver
drwxr-xr-x. 3 root root 35 Oct 27 10:18 maven-status
drwxr-xr-x. 2 root root 121 Oct 27 10:18 surefire-reports
drwxr-xr-x. 3 root root 19 Oct 27 10:18 test-classes
[root@ip-172-31-14-242 target]#
EDIT 2:
the mentioned jar file is there in /tmp
dir of the container file system. PSB
[root@ip-172-31-14-242 ~]# docker run -it cpa /bin/bash
[root@4018a6c2df8e /]# cd /tmp
[root@4018a6c2df8e tmp]# ll
total 17300
-rw-r--r--. 1 root root 17708542 Oct 27 10:19 gs-handling-form-submission-0.1.0.jar
-rwx------. 1 root root 836 Oct 6 19:15 ks-script-7RxiSx
-rw-------. 1 root root 0 Oct 6 19:14 yum.log
[root@4018a6c2df8e tmp]#
ANSWER
Answered 2018-Oct-29 at 09:12ENV PATH=$PATH:/usr/java/latest/bin/java
should probably be
ENV PATH=$PATH:/usr/java/latest/bin
I assume what is not being found is the java executable. Please check that java is really on the PATH.
What is ALSO wrong is this line:
CMD [ "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" ]
This should read:
CMD [ "java", "-jar", "/tmp/gs-handling-form-submission-0.1.0.jar" ]
Right now it is looking for a file called "java -jar /tmp/gs-handling-form-submission-0.1.0.jar" and tries to execute that.
QUESTION
As I followed this tutorial: https://spring.io/guides/gs/handling-form-submission/ after a while I came to a dead end. I tried to figure out what the problem is for some hours now. I hope you can help me.
When I submit my form, I get this error-message:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
My App (App.java):
package de.poc.logging.main;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
My Controller (InformationController.java):
package de.poc.logging.main;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/info")
public class InformationController {
@RequestMapping(method = RequestMethod.GET, produces = "text/html")
public String infoForm(Model model) {
model.addAttribute("information", new Information());
return "infoForm.html";
}
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String infoSubmit(@ModelAttribute Information information) {
return "infoResult.html";
}
}
I created an additional class for security (WebSecurityConf.java):
package de.poc.logging.main.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.headers()
.frameOptions().sameOrigin()
.httpStrictTransportSecurity().disable();
http.csrf().disable();
}
}
And I have following two HTML-Files:
infoForm.html:
Getting Started: Handling Form Submission
Form
Id:
Message:
infoResult.html:
Getting Started: Handling Form Submission
Result
Submit another message
Edit (additional information): my Information.java:
package de.poc.logging.main;
public class Information {
private long id;
private String content;
public long getId() {
return id;
}
public String getContent() {
return content;
}
public void setId(long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
}
my pom-dependencies:
junit
junit
org.springframework.boot
spring-boot-starter-web
1.5.2.RELEASE
org.springframework.boot
spring-boot-starter-test
test
1.5.2.RELEASE
org.springframework.boot
spring-boot-starter-security
1.5.2.RELEASE
I'm using Java 1.8u121 (jdk).
Edit2: I tried 3 different versions of spring boot now. Also I downloaded the project from here: https://github.com/spring-guides/gs-handling-form-submission and added spring boot via pom.xml. The downloaded project does not work for me.
I'm getting really frustrated.
ANSWER
Answered 2017-Mar-10 at 17:04Did you try with @RequestParam instead of @ModelAttribute?
Something like this..
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String infoSubmit(@RequestParam("info") Information information) {
return "infoResult.html";
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gs-handling-form-submission
You can use gs-handling-form-submission like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the gs-handling-form-submission component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page