1
2
3
4
5
6
7
8
9
10
11 package psiprobe.jsp;
12
13 import jakarta.servlet.jsp.JspException;
14 import jakarta.servlet.jsp.tagext.TagSupport;
15
16 import java.io.IOException;
17 import java.util.Collections;
18
19 import org.apache.commons.text.StringEscapeUtils;
20 import org.springframework.web.bind.ServletRequestUtils;
21
22
23
24
25 public class AddQueryParamTag extends TagSupport {
26
27
28 private static final long serialVersionUID = 1L;
29
30
31 private String param;
32
33
34 private String value;
35
36 @Override
37 public int doStartTag() throws JspException {
38 StringBuilder query = new StringBuilder();
39 query.append(param).append('=').append(value);
40 for (String name : Collections.list(pageContext.getRequest().getParameterNames())) {
41 if (!param.equals(name)) {
42 query.append('&').append(StringEscapeUtils.escapeHtml4(name)).append('=')
43 .append(StringEscapeUtils.escapeHtml4(
44 ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, "")));
45 }
46 }
47 try {
48 pageContext.getOut().print(query);
49 } catch (IOException e) {
50 throw new JspException("Exception printing query string to JspWriter", e);
51 }
52 return EVAL_BODY_INCLUDE;
53 }
54
55
56
57
58
59
60 public String getParam() {
61 return param;
62 }
63
64
65
66
67
68
69 public void setParam(String param) {
70 this.param = param;
71 }
72
73
74
75
76
77
78 public String getValue() {
79 return value;
80 }
81
82
83
84
85
86
87 public void setValue(String value) {
88 this.value = value;
89 }
90
91 }