한글 깨짐 필터
web.xml
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
class User
package com.java.dto;
public class User {
private String userId;
private String password;
private String name;
private String email;
public User() {
}
public User(String userId, String password, String name, String email) {
super();
this.userId = userId;
this.password = password;
this.name = name;
this.email = email;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User [userId=" + userId + ", password=" + password + ", name=" + name + ", email=" + email + "]";
}
}
class UserController
package com.java.web;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.java.dao.users.UserDao;
import com.java.dto.User;
@Controller
@RequestMapping("/users")
public class UserController {
private static final Logger logger=LoggerFactory.getLogger(UserController.class);
@Autowired
private UserDao userDao;
@RequestMapping("/form")
public String form(){
logger.debug("User : {} " , "test");
return "users/form";
}
@RequestMapping(value="", method=RequestMethod.POST)
public String create(User user){
logger.debug("User : {} " , user);
userDao.create(user);
logger.debug("Database : {} " , userDao.findById(user.getUserId()));
return "users/form";
}
}
댓글 ( 4)
댓글 남기기