我試圖用IntelliJ和gradle作爲構建工具來做一個簡單的應用程序。我用jstl庫的輸入做了一個簡單的面板,但是他們是我猜想的服務器的一些問題,因爲瀏覽器沒有顯示任何輸入。這是我的第一個Spring項目,我從來沒有使用過IntelliJ和Gradle,所以有可能我犯了一個愚蠢的錯誤,我無法解決。Java Spring IntelliJ jstl標籤不起作用
createUser.jsp(SRC /主/ web應用/ WEB-INF /觀看次數):
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dodaj usera</title>
</head>
<body>
<form:form method="POST" modelAttribute="userDTO">
<h1>Podaj imie: </h1>
<form:input type="text" path="name" /> <br />
<h1>Podaj nazwisko: </h1>
<form:input type="text" path="secondName" /> <br />
<h1>Podaj nr telefonu: </h1>
<form:input type="text" path="phoneNumber" /> <br />
<h1>Podaj e-mail: </h1>
<form:input type="text" path="eMail" /> <br />
</form:form>
</body>
</html>
controller.java:
@Controller
public class Controler {
@RequestMapping("/hello")
String hello(){
return "hello";
}
@RequestMapping(value = "/userForm", method = RequestMethod.GET)
String userFormGet(){
return "createUser";
}
@RequestMapping(value = "/userForm", method = RequestMethod.POST)
String userFormPost(@ModelAttribute("form") @Valid UserDTO userDTO, BindingResult result){
if(result.hasErrors()){
return "createUser";
}
else
return "redirect:/hello";
}
}
configuration.java類:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.petkow")
public class MvcConfiguration extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
build.gradle:
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'transport-service'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'org.hibernate:hibernate-validator:5.0.1.Final'
}
起動類:
@SpringBootApplication
public class TransportServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TransportServiceApplication.class, args);
}
}
數據傳輸對象類:
public class UserDTO {
@NotBlank
@Length(min=2, max=50)
private String name;
@NotBlank
@Length(min=2, max=50)
private String secondName;
@Min(9)
@Max(9)
private long phoneNumber;
@NotBlank
@Email
private String eMail;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSecondName() {
return secondName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String geteMail() {
return eMail;
}
public void seteMail(String eMail) {
this.eMail = eMail;
}
}
請分享[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 – CrazyCoder