发表于: 2018-02-06 23:51:54

1 618


今天在网页上输入数据,qqmajor都没有问题,但是名字的汉字总是乱码

解决次序是:1.tomcat里面加入红色的那句话

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"

                            useBodyEncodingForURI="true"  URIEncoding="UTF-8" />

用的是notepad++,如果用记事本,容易出问题。见图

 

2.依然是乱码,

<!-- 解决工程编码过滤器 -->
<filter>
  <filter-name>
characterEncodingFilter</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>
  <init-param>
    <param-name>
forceEncoding</param-name>
    <param-value>
true</param-value>
  </init-param>

web.xml里面如上一坨放在一排网址下面,因为次序会影响

再次在网页里加入数据,汉字可以识别了。

但是网页删除又删除不了了,很奇怪。


三。修改控制器:

@Controller
@RequestMapping("/student")
public class StudentController {
private static final Logger log = LoggerFactory.getLogger(StudentController.class);

   @Autowired
   private StudentService studentService;

   @RequestMapping("toAddStudent")
public String toAddStudent(){
return "addStudent";
   }

@RequestMapping("addStudent")
public String addStudent(Model model,Student student){
log.info("addStudent student :{}", student);
       System.out.println(""+student);
       if(student != null){
studentService.saveStudent(student);
       }
return "redirect:/student/getAllStudent";
       }

@RequestMapping("toEditStudent")
public String toUpdateStudent(){
return "editStudent";
   }

@RequestMapping("updateStudent")
public String UpdateStudent(Model model,Student student) {
if (studentService.updateStudent(student)) {
student = studentService.findStudentById(student.getId());
           model.addAttribute("student", student);
           return "redirect:/student/getAllStudent";
       }
return "/error";
   }
@RequestMapping("getAllStudent")
public String getAllStudent(Model model){

List<Student> students = studentService.findAll();
       model.addAttribute("studentList", students);
       return "allStudent";
   }
@RequestMapping("/getStudent")
public String getStudent(int id,Model model){
model.addAttribute("student",studentService.findStudentById(id));
       return "editStudent";
   }
@RequestMapping("/delStudent/{id}")
public String deleteStudent(@PathVariable int id,Model model){
studentService.deleteStudent(id);
       return "redirect:/student/getAllStudent";
   }


点击进入:

查,删除,跳转页面,增加,都成功了,就差一个改了。

改的editStudent.jsp文件是:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
   String path = request.getContextPath();
   String basePath = request.getScheme() + "://"
           + request.getServerName() + ":" + request.getServerPort()
           + path + "/";
%>
<html>
<title>编辑用户</title>
</head>
<body>
<h1>编辑用户</h1>
<form action="" name="studentForm">
   姓名:<input type="text" name="name"><br>
   QQ<input type="text" name="qq"><br>
   主修:<input type="text" name="major"><br>
   <input type="button" value="编辑"
          onclick="updateStudent()">
</form>
<script type="text/javascript">
   function updateStudent() {
var form = document.forms[0];
       form.action = "<%=basePath %>student/updateStudent";
       form.method = "post";
       form.submit();
   }
</script>
</body>
</html>

updateStudent.jsp文件是:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
   String path = request.getContextPath();
   String basePath = request.getScheme() + "://"
           + request.getServerName() + ":" + request.getServerPort()
           + path + "/";
%>
<!DOCTYPE html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
   <title>编辑用户</title>
 <script type="text/javascript">
       function updateStudent() {
var form = document.forms[0];
           form.action = "<%=basePath %>student/updateStudent";
           form.method = "post";
           form.submit();
       }
</script>
</head>
<body>
<h1>添加用户</h1>
<form action="" name="studentForm">
   <input type="hidden" name="id" value="${student.id }" /> 姓名:<input
       type="text" name="name" value="${student.name }" /> QQ<input
       type="text" name="qq" value="${student.qq }" /> 主修:<input
       type="text" name="major" value="${student.major }" /> <input type="button"
                                                                    value="编辑" onclick="updateStudent()" />
</form>
</body>
</html>


明天的计划:继续在网页上改

遇到的问题:还是没能实现在网页上改的目标

今天的收获:完成了增删查

java任务二开始时间:2018.01.25

预计demo时间:2018.02.12

可能有延期风险,原因是:基础比较差,

禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html



返回列表 返回列表
评论

    分享到