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.net.URLEncoder;
18 import java.nio.charset.Charset;
19 import java.util.Collections;
20
21 import org.springframework.web.bind.ServletRequestUtils;
22
23
24
25
26 public class ParamToggleTag extends TagSupport {
27
28
29 private static final long serialVersionUID = 1L;
30
31
32 private String param = "size";
33
34 @Override
35 public int doStartTag() throws JspException {
36 boolean getSize =
37 ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false);
38 StringBuilder query = new StringBuilder();
39
40 String encoding = pageContext.getResponse().getCharacterEncoding();
41 for (String name : Collections.list(pageContext.getRequest().getParameterNames())) {
42 if (!param.equals(name)) {
43 String value = ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, "");
44 String encodedValue = URLEncoder.encode(value, Charset.forName(encoding));
45 if (query.length() > 0) {
46 query.append('&');
47 }
48 query.append(name).append('=').append(encodedValue);
49 }
50 }
51
52 if (query.length() > 0) {
53 query.append('&');
54 }
55
56 query.append(param).append('=').append(!getSize);
57
58 try {
59 pageContext.getOut().print(query);
60 } catch (IOException e) {
61 throw new JspException("Exception printing query string to JspWriter", e);
62 }
63 return EVAL_BODY_INCLUDE;
64 }
65
66
67
68
69
70
71 public String getParam() {
72 return param;
73 }
74
75
76
77
78
79
80 public void setParam(String param) {
81 this.param = param;
82 }
83
84 }