我有兩個jsps,LoginSuccess.jsp和acctinfo.jsp。 在LoginSuccess.jsp,我設置所謂的用戶名與LoginSuccess.jsp一個有效的用戶名值的屬性更新:Http狀態500 - 此處禁止Scriptlets
我想實現的是:當用戶點擊超鏈接,它把控制權通過對acctinfo.jsp以下語句 其中url =「acctinfo.jsp」
在acctinfo.jsp中。我從會話中提取用戶名變量。我有一個名爲UserName的輸入字段,其值希望設置爲值=「<%= userName%>」
我喜歡看到的是用此userName值填充的輸入字段。相反,JSP編譯器抱怨但下列情況除外:
HTTP Status 500 - /acctinfo.jsp(36,66) Scripting elements (<%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet) are disallowed here.
這裏是LoginSuccess.jsp代碼:
<body>
<%
System.out.println("LoginSuccess.jsp: Entered LoginSuccess.jsp");
String username = request.getParameter("Username");
System.out.println("LoginSuccess.jsp: User Name from the request is: " + username);
session.setAttribute("Username", username);
String url2 = "acctinfo.jsp";
System.out.println("LoginSuccess.jsp: URL is: " + url);
//session.setAttribute("CustomerName", customerName);
%>
**<h3>Login successful.</h3>
<a href=<%= url2 %>>Proceed to Account Information Page</a>**
這裏是acctinfo.jsp代碼:
<%
String userName = (String) session.getAttribute("Username");
%>
<form name="ViewBalance" action="" method="POST">
<p>UserName: <input type=text NAME=UserName value="<%= userName %>">
</form>
下面是正確的代碼:「超鏈接到acctinfo.jsp」行確實在我的scr之外iplet塊,我仍然看到這個問題。 JSP編譯器仍然抱怨它不允許在這裏使用腳本元素。 我在這裏做錯了什麼?我想有人在這個問題上拋出更多的光
更新:我解決了問題,通過使用JSP EL和廢除Scriptlets。
在LoginSuccess.jsp: 我設置的屬性名在會話如下:
session.setAttribute("Username", username);
在我acctinfo.jsp我所做的:
<p>UserName: <input type=text NAME=UserName value="${sessionScope.Username}"></p>