简体   繁体   English

从servlet调用jsp页面而不使用会话变量

[英]calling jsp page from servlet not using session variable

Im trying to achive the requirement as below using netbeans, tomcat and servlet. 我正在尝试使用netbeans,tomcat和servlet达到以下要求。

I'm submitting the form to the servlet "Servlet1" with userid. 我正在使用用户ID将表单提交到Servlet“ Servlet1”。 and in Servlet1, I am creating the statusmessage based on userid I got from form and that needs to be displayed on "welcome.Jsp" page. 在Servlet1中,我根据从表单获得的用户ID创建状态消息,该状态消息需要显示在“ welcome.Jsp”页面上。

my servlet code : 我的servlet代码:

protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String nextPage = "";
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String statusMessage = "";
        String emailId = request.getParameter("EmailId");

        try {

           int i = 1;
            if (i != -1) {
                if (i >= 1) {
                    statusMessage = "User Authentication Success";


                } else {
                    statusMessage = "User Authentication failed";
                }
            } else {
                statusMessage = "ooooppppsssss";
            }

        } catch (Exception se) {
            out.println(se);
        }
        // out.print(statusMessage);
    RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");
    rd.forward(request, response);
}

Problem is : Im not redirected to the page where I want to display the message and instead url end up in the same page and not redirected. 问题是:我没有重定向到我要显示消息的页面,而是URL最终出现在同一页面中,并且没有重定向。 I know we can setit in session and can be access from enter code here "welcome.jsp" by response.sendredirect but Is there any way i can achive without using the session? 我知道我们可以在会话中进行setit,并且可以通过response.sendredirect从enter code here “ welcome.jsp”中enter code here进行访问,但是有什么方法可以不使用会话而实现?

You can set it as request attribute as 您可以将其设置为request属性为

request.setAttribute("idName",userid);

and access it in JSP using JSTL as ${idName} 并在JSP中使用JSTL作为${idName}访问它

What is the error you are getting?? 您遇到的错误是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM