查询字符串在传递到jsp页面的href时需要额外的字符

时间:2019-02-08 04:27:41

标签: java jsp query-string

我正在JSP的href中的查询字符串中传递参数。因此,当我单击链接后,它会提供一些额外的字符以及参数值。

String s="approved";
String activationcode=request.getParameter("activationcode");
if(activationcode!=null)
{
try
{
    Class.forName("oracle.jdbc.driver.OracleDriver");  
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","up78cp5317");  
    Statement stmt=con.createStatement();   
    stmt.execute("update (select Approval.status as st from Approval join Activity on Activity.userid=Approval.id where Activity.activationcode='"+activationcode+"') up set up.st='"+s+"'");
    //stmt.executeUpdate("UPDATE ( SELECT Approval.STATUS AS st FROM Approval JOIN Activity ON Activity.userid = Approval.id WHERE Activity.activationcode = '"+activationcode+"') up SET up.st = '"+s+"'");
    //stmt.executeUpdate("update (select Approval.status as st from Approval join Activity on Activity.userid=Approval.id where Activity.activationcode='"+activationcode+"') up set up.st='"+s+"'");      
    //stmt.executeUpdate("delete from activity where activationcode='"+activationcode+"'");
    stmt.close();
    con.close();
}

点击链接后,我得到的是: http://localhost:8090/TL/OnlineApprovalButton.jsp?activationcode=%2780f91f53-918f-45c4-9ee6-9eda9c40f72d%27

此处%27会添加参数值的开头和结尾

2 个答案:

答案 0 :(得分:0)

激活码的值可能以撇号(')开头,当您执行撇号的url编码时,其结果为%27。您可以在此处找到不同字符的网址编码。 https://www.w3schools.com/tags/ref_urlencode.asp

答案 1 :(得分:0)

我只是替换字符串,然后修剪字符串。

String activationcode=request.getParameter("activationcode").repalceAll("'"," ").trim();