0

I am passing data from ajax call to a specific JSP page. My login.jsp is receiving values. this is my jsp

<html>
<head>
    <title>Life Settlements</title>
</head>
    <body>
    <form action="login.ind" method="post">
    <% 
    String username = request.getParameter("loginUserName");
    System.out.println("username in jsp\t"+username);
    String password = request.getParameter("loginPaswd");
    %>
    </form>
</html>

The JSP is as getting username and password values. How do I pass this values to servlet.

My web.xml is as follows

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<servlet>
<servlet-name>ServletR</servlet-name>
<servlet-class>com.ind.servlet.RServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ServletR</servlet-name>
<url-pattern>*.ind</url-pattern>
</servlet-mapping>

  <welcome-file-list>
     <welcome-file>login.html</welcome-file>
  </welcome-file-list>
</web-app>

My servlet has service method as follows

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uri=request.getRequestURI();
        System.out.println(uri);
if (uri.endsWith("login.ind")) {
        page=loginAction.verifyUser(request, response);
    }}
Mukesh Kumar
  • 317
  • 1
  • 5
  • 16
  • 2
    Just get them the same way in servlet as you did in JSP? request.getParameter() etc. Unclear how ajax plays an role in your question. Perhaps this is helpful: http://stackoverflow.com/q/4112686 – BalusC Jan 24 '16 at 13:16

1 Answers1

0
<jsp:forward page="login.jsp" />
<jsp:param name="username" value="Tom"/>

  1. The page’s URL must be either relative to the current JSP page or relative to the web application’s context path (URL starts with a slash: /).
    1. The JSP forward action effectively terminates the execution of the current JSP page, so the forwarding should be used based on some dynamic conditions. For example: forward to an error page if an exception occurred or forward to a login page if the user has not logged in.
    2. The JSP/Servlet container will throw an HTTP 404 error if the forwarded page could not be found
Rahul Bhawar
  • 450
  • 7
  • 17