NullPointer
NullPointer

Reputation: 152

Why JSP is executed many times when a page is included in Struts 1?

I have tried to run the following code in Struts 1 and getting error.

<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE
        HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
        "http://www.w3.org/TR/html4/loose.dtd">         
<html> 
<jsp:include page="/Shop_login.jsp"></jsp:include>
<head>Welcome To My shop application </head> 
<body> 
  User Name:<html:input text="first_name"> </html:input>
  Password:<html:password text="password"> </html:password>  
</body>
</html>

Getting output as:

Welcome To My shop application User Name: Password: 
Welcome To My shop application User Name: Password: 
Welcome To My shop application User Name: Password: 
Welcome To My shop application User Name: Password:  ...

Upvotes: 0

Views: 352

Answers (1)

Roman C
Roman C

Reputation: 1

You could have these taglibs in the JSP, also if you use JSTL

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>

nothing more in the file just these fragments of code

then using

<%@ include file="/tags/taglibs.jsp" %>

at the top of the page, you can use the tags below the definition. Other JSP fragments you can include with JSTL, for example

<c:import url="/pages/page.jsp"/> 

or using JSP directive

<jsp:include page="/pages/page.jsp"/>

and don't use the same fragment inside itself, it may cause recursive calls in the servlet compiled from your code.

Upvotes: 1

Related Questions