简体   繁体   中英

Sending Information from a Servlet to a JSP

ok this is what I'm trying to do...I have 1 JSP page that gets 2 integers from a user. I use a form in this JSP so I can send the information to the servlet with the doGet method.

Then I want to take those numbers find the greatest common denominator and send that to another JSP. Getting the GCD isnt the issue right now, I'll just use function. But I cant figure out how to send anything to a new JSP.

    request.setAttribute("TEST", "TESTING");
    request.getRequestDispatcher("/WEB-INF/JSP2.jsp").forward(request, response);

Thats what I was playing around with to send information from the servlet to another JSP called JSP2. but whenever I hit submit on JSP (where I enter the numbers) I get an error.

Any help will be greatly appreciated

Show us the directory structure of your project. Make an index.jsp page saying hello and see if you can access it.

How do you deploy the application, show us the .war unzipped contents.

Your idea to use the requestDispatcher is correct, as well as adding stuff to the request, and later in another servlet/jsp using them. Note that if you access the index.jsp by server:port/index.jsp then the requestDispatcher argument should also be "your.jsp" and not "WEB-INF/the.jsp", ie remove the WEB-INF.

如果您的表单正在POST到servlet,您是否应该实现doPost而不是doGet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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