在我的其中一個資源中,我通過會話響應將JSON對象傳遞給JSP頁面。在響應中阻止URL編碼
@POST
@Path("/updateUser")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response userProfile(
@Context UriInfo uriInfo, String updateProfileData,
@Context HttpServletRequest req
) throws JSONException, UnsupportedEncodingException {
String session = req.getSession(true).getId();
JSONObject jsOb = new JSONObject(updateProfileData);
JSONArray jaArr = jsOb.getJSONArray("profileData");
JSONObject a;
StringBuilder sbv = new StringBuilder();
StringBuilder sbk = new StringBuilder();
String prefix = "";
try {
conn = DaoMessenger.PostGresCon().getConnection();
for (int i = 0; i < jaArr.length();) {
JSONObject jsonObject = jaArr.getJSONObject(i);
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
Object value = jsonObject.get(key);
sbk.append(prefix);
sbv.append(prefix);
prefix = ",";
sbv.append("'").append(value).append("'");
sbk.append(key);
}
query = conn.prepareStatement("INSERT INTO addresses (" + sbk.toString() + ") values (" + sbv.toString() + ")");
System.out.println("QUERY: " + query);
rs = query.executeUpdate();
System.out.println("RS: " + rs);
i++;
System.out.println("rowsUpdated: " + rs);
}
} catch (Exception e){
e.printStackTrace();
}
if (rs > 0) {
System.out.println("SUCCESS");
URI uri;
uri = uriInfo.getBaseUriBuilder()
.path("../home/index.jsp?page/#/home")
.queryParam("obj", URLEncoder.encode(updateProfileData, "UTF-8"))
.build();
return Response.seeOther(uri).build();
} else {
System.out.println("STUCK SOMEWHERE");
URI uri = uriInfo.getBaseUriBuilder()
.path("/messenger/home/index.jsp?page/#/error;" + req.getSession(true).getId()).build();
return Response.seeOther(uri).build();
}
}
,但我一直面臨
404錯誤
的URL被編碼和路徑了。 所以:?
變爲:%3F
和#
變爲:
而不是%23
:http://localhost:8080/messenger/home/index.jsp?page/#/home
我得到:http://localhost:8080/messenger/home/index.jsp%3Fpage/%23/home
第二個是不是爲我工作,並導致404錯誤。我通過谷歌搜索嘗試了幾個解決方案,但都沒有幫助。
如何在將響應發送到JSP頁面後強制這樣保持路徑的原始字符?
你可以把它回來URLDecoder.decode的URL重定向到瀏覽器之前解碼 – mhasan
你能[編輯]你的問題你如何展現」在對客戶端的響應中包含構造的URI? – Kenster
@mhasan:我試了一下,但沒有成功 –