Skip to content

Commit 5ad1c58

Browse files
committed
fix fastjson
1 parent 7ba2e49 commit 5ad1c58

File tree

16 files changed

+156
-68
lines changed

16 files changed

+156
-68
lines changed

.idea/workspace.xml

Lines changed: 37 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
### Docker启动
1515

16-
```git
16+
```
1717
git clone https://github.com/tangxiaofeng7/SecExample.git
1818
cd SecExample
1919
docker-compose up -d
@@ -26,20 +26,25 @@ docker-compose up -d
2626
### 本地调试
2727

2828
##### 下载源码:
29-
```git
29+
```
3030
git clone https://github.com/tangxiaofeng7/SecExample.git
3131
```
3232
##### 使用idea导入
3333

3434
##### 编辑 src/main/resources/application.yml 的数据库配置
3535
```
36-
# url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useSSL=false
37-
url: jdbc:mysql://mysql-db:3306/mybatis?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
36+
#url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useSSL=false
37+
url: jdbc:mysql://mysql-db:3306/mybatis?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
3838
```
3939
修改为
4040
```
41-
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useSSL=false
42-
# url: jdbc:mysql://mysql-db:3306/mybatis?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
41+
url: jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&useSSL=false
42+
#url: jdbc:mysql://mysql-db:3306/mybatis?serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
43+
```
44+
并且修改mysql用户名密码
45+
```
46+
username: root
47+
password: 你的mysql密码
4348
```
4449
##### 本地启动mysql数据库
4550
启动数据库:

src/main/java/com/suyu/secexample/fastjson/controller/fastjsoncontroller.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,42 @@
22

33
import com.alibaba.fastjson.JSON;
44
import com.alibaba.fastjson.JSONObject;
5-
import com.alibaba.fastjson.parser.Feature;
6-
import com.alibaba.fastjson.serializer.SerializerFeature;
75
import com.suyu.secexample.fastjson.model.User;
86
import org.springframework.stereotype.Controller;
97
import org.springframework.ui.Model;
108
import org.springframework.web.bind.annotation.*;
119

10+
1211
@Controller
1312
public class fastjsoncontroller {
1413

1514
@GetMapping("/fastjson")
1615
public String input(){
17-
18-
User user = new User();
19-
user.setAge("18");
20-
user.setUsername("txf");
21-
String ser1 = JSON.toJSONString(user);
22-
System.out.println(ser1);
23-
String ser2 = JSON.toJSONString(user, SerializerFeature.WriteClassName);
24-
System.out.println(ser2);
16+
//
17+
// User user = new User();
18+
// user.setAge("18");
19+
// user.setUsername("txf");
20+
// String ser1 = JSON.toJSONString(user);
21+
// System.out.println(ser1);
22+
// String ser2 = JSON.toJSONString(user, SerializerFeature.WriteClassName);
23+
// System.out.println(ser2);
2524
return "fastjson/fastjson";
2625
}
2726

28-
@PostMapping("/fastjsonoutput")
29-
public String outputmessage(@RequestParam("data") String data, Model model){
30-
JSONObject ser2 = JSON.parseObject(data, Feature.SupportNonPublicField);
31-
JSONObject result = new JSONObject(ser2);
32-
result.put("18",ser2.get("name"));
33-
model.addAttribute("result",result);
27+
User user = new User();
28+
29+
@RequestMapping ("fastjson")
30+
public String fastjson1(@RequestBody String jsonData, Model model) {
31+
JSONObject jsonObject = JSON.parseObject(jsonData);
32+
user.setAge(jsonObject.get("age").toString());
33+
user.setUsername(jsonObject.get("username").toString());
34+
model.addAttribute("result",user);
35+
return "fastjson/fastjsonoutput";
36+
}
37+
38+
@RequestMapping ("fastjson2")
39+
public String fastjson2( Model model) {
40+
model.addAttribute("result",user);
3441
return "fastjson/fastjsonoutput";
3542
}
3643
}

src/main/java/com/suyu/secexample/messageecho/controller/messagecontroller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public String getcode(Model model){
2828

2929
@PostMapping("/messageecho/testcode")
3030
public String testcode(Integer code1,Model model){
31-
String result ="登陆失败";
31+
String result ="fail";
3232
if (code1 != null && code1 != 0 &&Code == code1){
3333
System.out.println(true);
34-
result ="登陆成功";
34+
result ="sueecss";
3535
}
3636
model.addAttribute("code1",result);
3737
return "messageecho/messageechooutput";

src/main/resources/templates/fastjson/fastjson.html

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<meta charset="UTF-8">
55
<title>Java漏洞靶场</title>
66
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
7+
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
78
</head>
9+
10+
811
<body>
912

1013
<div style="padding: 40px;
@@ -15,17 +18,43 @@ <h1>Java漏洞演示平台</h1>
1518
<button class="ui inverted secondary basic button"><a style="color: white" th:href="home">回到首页</a></button>
1619
</div>
1720

21+
<div style="text-align: center;margin: 0px auto;
22+
margin-top: 50px;">
23+
<input id="username" type="text" placeholder="请输入用户名">
24+
<input id="age" type="text" placeholder="请输入年龄">
25+
<input id="start" type="submit" value="提交">
26+
<p></p>
27+
</div>
1828

1929

30+
<script>
31+
$("#start").click(function () {
32+
var user= {
33+
"username" : $("#username").val(),
34+
"age" : $("#age").val()
35+
};
36+
$.ajax({
37+
type : "POST",
38+
async : true,
39+
contentType: "application/json; charset=utf-8",
40+
data : JSON.stringify(user),
41+
dataType : 'json',
42+
success : function(){
43+
       alert('成功');
44+
window.location.href ="../fastjson2";
45+
},
46+
error : function(){
47+
       alert('确定');
48+
window.location.href ="../fastjson2";
49+
},
50+
})
51+
}
52+
);
53+
54+
</script>
2055

21-
<form th:action="@{/fastjsonoutput}" method="post" style="text-align: center;margin: 0px auto;
22-
margin-top: 50px;" border="10">
23-
<input type="text" name="data" placeholder="请输入用户名查找">
24-
<input type="submit" value="提交">
25-
<p></p>
26-
<p>提示:{"age":18,"username":"txf"}</p>
27-
</form>
2856

2957

3058
</body>
31-
</html>
59+
</html>
60+

src/main/resources/templates/fastjson/fastjsonoutput.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ <h1>Java漏洞演示平台</h1>
1818
<div style="text-align: center;margin: 0px auto;
1919
margin-top: 50px;">结果为:<p th:text="${result.username}"></p>今年<p th:text="${result.age}"></p>
2020

21-
2221
</div>
23-
24-
2522
</body>
2623
</html>

src/main/resources/templates/messageecho/messageecho.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ <h1>Java漏洞演示平台</h1>
1515
<button class="ui inverted secondary basic button"><a style="color: white" th:href="home">回到首页</a></button>
1616
</div>
1717

18-
19-
20-
21-
<form style="text-align: center;margin: 0px auto;margin-top: 50px;" border="10">
18+
<div style="text-align: center;margin: 0px auto;margin-top: 50px;" border="10">
2219
<div class="ui input">
2320
<input type="text" name="tele" placeholder="手机号码">
2421
<a class="ui button" th:href="@{/messageecho/getcode}">获取验证码</a>
2522
</div>
26-
</form>
27-
23+
</div>
2824

2925
</body>
3026
</html>
Binary file not shown.
Binary file not shown.

target/classes/templates/fastjson/fastjson.html

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<meta charset="UTF-8">
55
<title>Java漏洞靶场</title>
66
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css">
7+
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
78
</head>
9+
10+
811
<body>
912

1013
<div style="padding: 40px;
@@ -15,17 +18,43 @@ <h1>Java漏洞演示平台</h1>
1518
<button class="ui inverted secondary basic button"><a style="color: white" th:href="home">回到首页</a></button>
1619
</div>
1720

21+
<div style="text-align: center;margin: 0px auto;
22+
margin-top: 50px;">
23+
<input id="username" type="text" placeholder="请输入用户名">
24+
<input id="age" type="text" placeholder="请输入年龄">
25+
<input id="start" type="submit" value="提交">
26+
<p></p>
27+
</div>
1828

1929

30+
<script>
31+
$("#start").click(function () {
32+
var user= {
33+
"username" : $("#username").val(),
34+
"age" : $("#age").val()
35+
};
36+
$.ajax({
37+
type : "POST",
38+
async : true,
39+
contentType: "application/json; charset=utf-8",
40+
data : JSON.stringify(user),
41+
dataType : 'json',
42+
success : function(){
43+
       alert('成功');
44+
window.location.href ="../fastjson2";
45+
},
46+
error : function(){
47+
       alert('确定');
48+
window.location.href ="../fastjson2";
49+
},
50+
})
51+
}
52+
);
53+
54+
</script>
2055

21-
<form th:action="@{/fastjsonoutput}" method="post" style="text-align: center;margin: 0px auto;
22-
margin-top: 50px;" border="10">
23-
<input type="text" name="data" placeholder="请输入用户名查找">
24-
<input type="submit" value="提交">
25-
<p></p>
26-
<p>提示:{"age":18,"username":"txf"}</p>
27-
</form>
2856

2957

3058
</body>
31-
</html>
59+
</html>
60+

0 commit comments

Comments
 (0)