2 回答

TA貢獻2019條經驗 獲得超9個贊
在包中創建一個擴展名為“.properties”的屬性文件,并通過在 jsp 中導入資源包包來使用在 jsp 文件中定義的那些屬性。
config.properties
name=priya
phone=22222
示例.jsp
<%@ page import = "java.util.ResourceBundle" %>
<% ResourceBundle resource = ResourceBundle.getBundle("config");
String name=resource.getString("name");
String email=resource.getString("email");
String phone=resource.getString("phone");
%>
Name: <input type="text" id="name" value="<%=name %>">
Email: <input type="text" id="email" value="<%=email %>">
Phone: <input type="text" id="phone" value="<%=phone %>">

TA貢獻1796條經驗 獲得超4個贊
一個經典的 JSP。在這里我使用%><%所以仍然沒有輸出被寫入,并且可以重定向到另一個頁面。
HTTP 首先發送一些標題行,一個空行,然后是可選的 HTML 內容。進行重定向將是標題行。所以仍然沒有內容必須由 JSP 編寫。標題行可以說明使用的字符集/編碼、cookie 等。
所以:
<%@ page import = "java.util.ResourceBundle"
%><%
ResourceBundle resource = ResourceBundle.getBundle("config");
String names = resource.getString("name");
String[] env = resource.getString("envs").split(",\\s*");
String turls = resource.getString("tokenurl");
String tech = request.getParameter("tech");
if (tech != null && tech.equals("google")) {
String url = response.encodeRedirectURL(env[13]);
response.sendRedirect(url); // Just tell the browser to redirect, load the url.
return;
}
%>
不幸的是,實際的邏輯是你的事。與 JavaScript 相比,s == 'abc'有s.equals("abc").
學習和使用 JSP 標記和 EL(表達式語言)將使代碼更小。
使用 servlet 作為控制器,準備數據,然后作為視圖轉發到任何 JSP ,使用數據參數化(或重定向到某些外部 URL),模型會更好。
添加回答
舉報