-2
嗨我可以在我的jsp中獲取會話值,現在我想比較會話值是否匹配文本框,如果匹配,它會將用戶重定向到另一個頁面否則它將保持相同的頁面,我不知道如何繼續,請幫助。非常感謝!比較會話值是否與文本框的值相匹配
JSP
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Factorial</title>
</head>
<body>
<form action="fact" method="POST">
Enter a number: <input type="text" name="num">
<input type="submit"/>
<%= session.getAttribute("money") %>,
</form>
</body>
</html>
的Servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
String text = request.getParameter("money");
int money = (Integer)session.getAttribute("money");
String testing = String.valueOf(money);
if(text == testing)
{
RequestDispatcher rd = request.getRequestDispatcher("MainPage");
rd.forward(request, response);
}
else
{
response.redirect("Errorpage.jsp");
}
請提供您的代碼示例,並解釋您到目前爲止所嘗試的內容。 <!DOCTYPE HTML> – deyur 2014-10-02 03:11:00
可能重複的[如何比較Java中的字符串?](http:// stacko ver10.com/questions/513832/how-do-i-compare-strings-in-java) – 2014-10-02 12:33:53