JSP + Servlet in which can't find the page.

I have a JSP page and the servlet.


<form name="wizard" method="POST" action="/ServiceRequest" onsubmit="return checkData()">


srServlet
==
public class ServiceRequestServlet extends HttpServlet {

      private static final Log log = LogFactory.getLog(ServiceRequestServlet.class);
      protected void doGet(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
            log.debug("doGet - Start");
            doWork(request,response);
      }

      protected void doPost(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
            log.debug("doPost - Start");
            doWork(request,response);
      }

      public void doWork(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException {

            log.debug("doWork - Start");
            ServiceRequestProcessorLocal order = initializeController();
            handleRequest(request, response, order);
            viewAllBookings(request, order);
            HttpSession session = request.getSession(true);
            RequestDispatcher dispatcher = request.getRequestDispatcher("/customer/createSR_action");
            try {
                  dispatcher.forward(request, response);
            } catch (IOException e) {
                  e.printStackTrace();
                  throw new ServletException(e.getMessage());
            }
      }
==========================================================

web.xml


    <servlet-mapping>
        <servlet-name>ServiceRequestServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
 
    <servlet-mapping>
        <servlet-name>createSR_action.jsp</servlet-name>
        <url-pattern>/customer</url-pattern>
    </servlet-mapping>


=================================================================
please advise why it can't find the createSR_action.jsp page
LeanMoreTryMoreAsked:
Who is Participating?
 
suprapto45Connect With a Mentor Commented:
Hi,

I think that
<form name="wizard" method="POST" action="/ServiceRequest/servlet">
shoud work fine.

And
>>"    <servlet>
        <servlet-name>createSR.jsp</servlet-name>
        <jsp-file>/customer/createSR.jsp</jsp-file>
    </servlet>"
You do not need this. You can remove it from your web.xml.

David
0
 
suprapto45Commented:
Hi,

>>"RequestDispatcher dispatcher = request.getRequestDispatcher("/customer/createSR_action");"
You are not calling createSR_action.jsp but instead you are calling createSR_action. Is it a Servlet again?

>>"    <servlet-mapping>
        <servlet-name>createSR_action.jsp</servlet-name>
        <url-pattern>/customer</url-pattern>
    </servlet-mapping>"
I do not think that it is necessary. Why do you want to map a JSP as a servlet?

David
0
 
LeanMoreTryMoreAuthor Commented:
yes.
the servlet is mainly used to call the ejb application to be used to insert and send email, then it redirect to a jsp page as a confirmation page.

so what do u suggest?

please advise.

first time to build the web page using jsp.
I used to build the bean and backend applicaiton.

so i dont know all these

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
LeanMoreTryMoreAuthor Commented:
how do i know the servlet is called?
0
 
suprapto45Commented:
Try to change

RequestDispatcher dispatcher = request.getRequestDispatcher("/customer/createSR_action");
into
RequestDispatcher dispatcher = request.getRequestDispatcher("/customer/createSR_action.jsp");

assuming that after everything is executed, you are going to createSR_action.jsp.

Then you can remove those entries that I mentioned before in your web.xml.

David
0
 
LeanMoreTryMoreAuthor Commented:
Not working dont know why
I guess in JSP page, where the Submit button is clicked, it calls

   <form name="wizard" method="POST" action="/ServiceRequest" onsubmit="return checkData()">
         <input type="hidden" name="appAction" value="<%=Constants.ACTION_SAVE%>"/>

The URL on web browser shown
http://myc029736:50000/ServiceRequest


The requested resource does not exist.
  Details:   Go to main page of this application!
 
 
0
 
LeanMoreTryMoreAuthor Commented:
make it easy the servlet outputs the information in which shows the confirmation page.

HOw can i do that?
0
 
LeanMoreTryMoreAuthor Commented:
I dont think the ServiceRequestServlet.jar get called...
0
 
suprapto45Commented:
Okay,

>>"   <form name="wizard" method="POST" action="/ServiceRequest" onsubmit="return checkData()">
        <input type="hidden" name="appAction" value="<%=Constants.ACTION_SAVE%>"/>"

Do you have the submit button as

   <form name="wizard" method="POST" action="/ServiceRequest" onsubmit="return checkData()">
        <input type="hidden" name="appAction" value="<%=Constants.ACTION_SAVE%>"/>
        <input type="submit" name="submit" value="submit" />

Then try to change your web.xml as

    <servlet-mapping>
        <servlet-name>ServiceRequestServlet</servlet-name>
        <url-pattern>/ServiceRequest</url-pattern>
    </servlet-mapping>

And do you have something like below in your web.xml?

    <servlet>
        <servlet-name>ServiceRequestServlet</servlet-name>
        <servlet-class>whatever.package.here</servlet-class>
    </servlet>
0
 
LeanMoreTryMoreAuthor Commented:
Your guess is exactly right.

In my JSP page, it does have a Submit button like below


   <form name="wizard" method="POST" action="/ServiceRequest" onsubmit="return checkData()">
.
.
                    <td align="center" bgcolor="DEE3E9">
                        <input type="submit" name="srAdd" value="Submit" >
                    </td>

====================================================================
In my web.xml

For servlet mapping
-----------------------
      <servlet-mapping>
            <servlet-name>ServiceRequestServlet</servlet-name>
            <url-pattern>/</url-pattern>
      </servlet-mapping>


For servlet tag

      <servlet>
            <servlet-name>ServiceRequestServlet</servlet-name>
            <servlet-class>com.ieg.servicerequest.servlet.ServiceRequestServlet</servlet-class>
      </servlet>

=====================================================
so what should i do based on the above setting in web.xml
0
 
suprapto45Commented:
Try to change your web.xml into

     <servlet-mapping>
          <servlet-name>ServiceRequestServlet</servlet-name>
          <url-pattern>/ServiceRequest</url-pattern>
     </servlet-mapping>

and try again
0
 
LeanMoreTryMoreAuthor Commented:
I change to:

      <servlet-mapping>
            <servlet-name>ServiceRequestServlet</servlet-name>
            <url-pattern>/ServiceRequest</url-pattern>
      </servlet-mapping>

and run, i got different error

You are not authorized to view the content of the requested directory.
  Details:   Directory listing is not allowed on this server.
 
 

NOtes: After i deploy to EAR and modify the application.xml to

<application>
      <display-name>ServiceRequestApplication</display-name>
      <description>Modules for online service request</description>
      <module>
            <ejb>SRejb.jar</ejb>
      </module>
      <module>
            <web>
                  <web-uri>SRweb.war</web-uri>
                  <context-root>/ServiceRequest</context-root>
            </web>
      </module>
</application>

**** THE WEB context-root is /ServiceRequest  ...
is it crashed?
0
 
LeanMoreTryMoreAuthor Commented:
so i changed to

      <servlet>
            <servlet-name>ServiceRequestServlet</servlet-name>
            <servlet-class>com.ieg.au.servicerequest.servlet.ServiceRequestServlet</servlet-class>
      </servlet>
      <servlet-mapping>
            <servlet-name>ServiceRequestServlet</servlet-name>
            <url-pattern>/ServiceRequest/servlet</url-pattern>
      </servlet-mapping>

in Jsp

<form name="wizard" method="POST" action="/ServiceRequest/servlet" onsubmit="return checkData()">


but i got the following error

The request cannot be processed.
  Details:   com.sap.engine.services.servlets_jsp.server.exceptions.ServletNotFoundException: Requested resource [/ServiceRequest/servlet] not found.
 
 
0
 
suprapto45Commented:
Hi,

I believe that this is related to your SAP NetWeaver so I am not really sure.

Look at this URL.
https://www.sdn.sap.com/irj/sdn/message?messageID=2656875
0
 
suprapto45Commented:
>>"The request cannot be processed.
  Details:   com.sap.engine.services.servlets_jsp.server.exceptions.ServletNotFoundException: Requested resource [/ServiceRequest/servlet] not found."

For this error, try to restart your server and try again. Sometimes, it is not deploying successfully.
0
 
rrzConnect With a Mentor Commented:
>**** THE WEB context-root is /ServiceRequest  ...  
><url-pattern>/ServiceRequest/servlet</url-pattern>
In this case, instead of  using  
> <form name="wizard" method="POST" action="/ServiceRequest/servlet"
you should use  
><form name="wizard" method="POST" action="ServiceRequest/servlet"
or
<form name="wizard" method="POST" action="/ServiceRequest/ServiceRequest/servlet"
0
 
LeanMoreTryMoreAuthor Commented:
** i found the reason why it can't find the page

The url shown

http://myc029736:50000/ServiceRequest/customer/ServiceRequest/servlet

instead of
http://myc029736:50000/ServiceRequest/servlet


When I manually type the URL from the web browser http://myc029736:50000/ServiceRequest/servlet, the servlet has been called the page.

But i dont know how to fix

In web.xml, the servlet tag for the jsp page is


That's why when the createSR.jsp is called, the URL is http://myc029736:50000/ServiceRequest/customer/createSR.jsp

    <servlet>
        <servlet-name>createSR.jsp</servlet-name>
        <jsp-file>/customer/createSR.jsp</jsp-file>
    </servlet>
0
 
LeanMoreTryMoreAuthor Commented:
very thanks for all your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.