Link to home
Start Free TrialLog in
Avatar of Arthur Wang
Arthur WangFlag for United States of America

asked on

how to make dynamic form url in JSP

I have a legacy system developed 10 years ago.

 A jsp page---SalesEditBillingAddress.jsp

<jsp:include page="/WEB-INF/forms/include/edit_billing_address.jsp" > 
<jsp:param name="dept" value="sales"/>
</jsp:include>    

Open in new window


second jsp page---marketingEditBillingAddress.jsp

<jsp:include page="/WEB-INF/forms/include/edit_billing_address.jsp" > 
<jsp:param name="dept" value="marketing"/>
</jsp:include>    

Open in new window


The reason to pass the parameter is because the generic page----edit_billing_address.jsp has different form action need to be submitted based on different parameters.

  <html:form action="/actions/${param.dept}/editBillingAddress">
<html:text name="customerBillingAddressBean" property="address1"  maxlength="60"> </html:text> 
.............
<html:text name="customerBillingAddressBean" property="contact" maxlength="60"></html:text>
<html:text name="customerBillingAddressBean" property="email" maxlength="80"></html:text>

<button type = "submit" class ="btn btn-primary">Submit</button>		   
</html:form>        

Open in new window



however, tomcat 8.0 with java 1.8 complain about this line of code:
<html:form action="/actions/${param.dept}/editBillingAddress">

Open in new window


javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot retrieve mapping for action /actions/${param.dept}/editBillingAddress

The example on this page:

http://beginnersbook.com/2013/12/jsp-include-with-parameter-example/

shows that my code is nothing wrong about it.

my question is: how to make the parameter work in the action URL?

I also tried the following code:

			 
			 <c:set var="myVar" value="${param.dept}" />

			 <c:if test = "${myVar eq 'sales'}">
			   <html:form action="/actions/sales/editBillingAddress">  
			 </c:if>
		    
		        <c:if test = "${myVar eq 'marketing'}">
			   <html:form action="/actions/marketing/editBillingAddress">
		         </c:if>

                ............. many input fields ...............

                        <button type = "submit" class ="btn btn-primary">Submit</button>		           
	                </html:form>        
	  

Open in new window


but it doesn't work because the eclipse compiler give error message due to only one closed form tag could be found.
Avatar of Arthur Wang
Arthur Wang
Flag of United States of America image

ASKER

I discovered another problem after searching around .

My jstl jar file placed in the lib folder of the project is: jstl-1.2.jar, but my old working code:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

not working any more, instead I have to change every web page to use the following line:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>

and my web.xml file is like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">

Open in new window


Based on this page:

https://stackoverflow.com/questions/31355583/difference-between-http-java-sun-com-jsp-jstl-core-and-http-java-sun-com-jst

I have to change the facet, but from Project-->Properties --> project facets, it shows Dynamic web Module 2.3, I am trying to change it, but Eclipse does NOT allow me to change it.

what is wrong with my project setting? I am thinking if I could go back to jstl 1.2 instead of the deprecated 1.0, my original problem/question might be solved.
Screen-Shot-2017-06-09-at-12.01.43-A.png
ASKER CERTIFIED SOLUTION
Avatar of Arthur Wang
Arthur Wang
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial