user3756474
user3756474

Reputation: 15

Pass variable servlet to jsp page appengine project

I try to pass a simple string variable to my page index.jsp but without success:

@SuppressWarnings("serial")
public class HexoSkin_GAEServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
        String dateStr = "2014.07.07.19:40";
        request.setAttribute("dateStr", dateStr);

        // I try
        this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);

        // Or
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}

My index.jsp is under the folder "war." My project is a web application project (appengine) And in my page.jsp:

<% 
    String attribut = (String) request.getAttribute("dateStr");
    // Return always null
    out.println("VALUE :" +attribut);
%>

I also tried Session:

request.getSession().setAttribute("dateStr",dateStr);
String attribut2 =  (String) session.getAttribute("dateStr") ;

Here's my web.xml in case it helps:

<servlet>
    <servlet-name>HexoSkin_GAE</servlet-name>
    <servlet-class>myapp.HexoSkin_GAEServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HexoSkin_GAE</servlet-name>
    <url-pattern>/hexoskin_gae</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>

Did I miss some configuration part? Thanks

Upvotes: 0

Views: 291

Answers (2)

Alok Pathak
Alok Pathak

Reputation: 875

you are trying to display value in page.jsp but actually you are redirecting request to index.jsp.

Upvotes: 1

Gas
Gas

Reputation: 18030

You didn't write, what was the problem (no value or exception). Try to use either:

request.getRequestDispatcher("index.jsp").forward(request, response);

or

getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);

Because method from ServletContext only allows path starting with the /

See documentation.

Upvotes: 0

Related Questions