I am a beginner with jsp servlets, and I need some help having my page not show up blank when I make changes. I am trying to include the the code from a donate-box.jsp into the layout of the org-about-panel.jsp page, which itself is included in another view jsp file. When I makes change to donate-box, then load the view file, I am seeing a blank site, and then upon refreshing, it shows up as before without the donate-box.
Here is the code I am trying to include, from the donate-box:
<logic:notEqual name="hideDonateBox" value="true">
<form action="https://<%=request.getServerName()%><%=contextPath%>/cartDonate.do method="get">
<input type="hidden" name="targetPage" value="<%=requestedPathWithQuery%>">
<div class="donateBox">
<logic:notEmpty name="detailOrgBean" property="offerings">
<table class="donateBox" cellpadding="0" cellspacing="0">
<logic:iterate name="detailOrgBean" property="relatedOfferings" id="receiver" indexId="oppIndex" length="5">
<tr class="donateBox">
<td class="donateBox">
<input type="radio" name="receiverId"
value="<bean:write name="receiver" property="id"/>">
</td>
<th class="donateBox" align="right">
$ -
/donate/<%= formatter.getUrlPath((Receiver) receiver) %>">
" CHECKED>
">
$ (Other)
This file is being included in another file with this code. I have tried commenting out the logic:notequal or logic:empty tags.
<%# include file="/templates/donate-box.jsp" %>
Thanks in advance!
This problems appears because your jsp (donate-box) can't be compiled (Such behavior I've seen in tomcat).
From quick look, I can say that requestedPathWithQuery - variable is undefined in scripting.
For more precise description you can take a look in logs
Related
When expanding a HTML page with embedded variables from JSP code my code produced inexplicable results. The variable "String completename" expands at first to
http://www.formatika.de/cococo.de/products/Sources/Isabelle/Doc/Tutorial/document/Isa-logics.pdf
and 2 lines later to
http://localhost:8080/cococo.de/products/Sources/Isabelle/Doc/Tutorial/document/Isa-logics.pdf
in the following code fragment:
<div>
<table border="0" align="center" cellspacing="2" cellpadding="2">
<tr align="center"><td align="center">
<div>
<a href="<%=completename %>" title="<%=showname%>" target="_blank"><%=filename%><br><br>
<iframe src='<%=completename %>' width='<%=width%>' height='<%=height%>' type='application/pdf'>
</iframe>
</a>
</div>
</td></tr>
</table>
</div>
it can be observed in this URL
http://formatika.de/print.jsp?content=source&file=products/Sources/Isabelle/Doc/Tutorial/document/Isa-logics.pdf
Does anyone know where to search? I use Apache Tomcat 8.0.27 with JAVA EE 6 Web.
Found the answer/bug; it was because the Tomcat still is hidden behind the IIS and therefore the name was here resolved to "localhost:8080" instead of the hostname at IIS.
I'm making a form to add events to a list but I need to be able to see in that form the previous events from that list. I have a jsp that shows a list of events but it takes an attribute usually added by the controller when you access the list directly from the browser.
So how can I add the list jsp filling that attribute so it shows a list and not just the headers?
I have alreay included the jsp using
<jsp:include page="comp_list.jsp"></jsp:include>
And it shows the headers but as there is no attribute it shows no list. I tried adding attributes to the include like:
<jsp:include page="comp_list.jsp">
<jsp:attribute name="compensaciones">
${compensaciones}
</jsp:attribute>
</jsp:include>
But when I do it it shows an error telling me that this cannot be done.
Also tried params but that would not be the answer for me because params are treated in the controller and not in the jsp itself.
I'm just getting the header of the list which is fine, but i would like to see the list.
Edit: this is how i build the list in case you are wondering
<tbody>
<c:forEach var="comp" items="${compensaciones}">
<td>${comp.getSomething()}</td>
...
</c:forEach>
</tbody>
<jsp:include page="pagename.jsp" />
i thing you are not provide extension in your include tag
Sometimes since I've had prior experience back in the days with HTML and PHP, we simply just would include things like navigation and header for easier management.
I'm unsure for what purpose you're including JSP, but here's an example of how I've done it since I include JSP if a boolean is true.
The site that is accessed:
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-8">
<%
if (loggedin) {
%>
<%# include file="includes/profile.jsp" %>
<% } else {
out.println("<div><h2>You aren't logged in!</h2></div>");
}
%>
</div>
<div class="col-lg-2">
</div>
</div>
And the top and bottom of the JSP file I'm including doesn't contain things like head, title, html, body etc.
<%
User currUser = null;
currUser = (User) session.getAttribute("user");
%>
<div>
<h2>Du er logget ind, velkommen <% out.println(currUser.getUsername().toUpperCase()); %></h2> <br>
<h5>Din Saldo: <b><% if (currUser.getBalance() < 0) { out.println("<font color='red'>" + currUser.getBalance() + "</font>");} else { out.println("<font color='green'>" + currUser.getBalance() + "</font>");} %></b></h5>
<br>
<form class="form" method="post" action="#">
<h4>Oplysninger: </h4>
<h6>
For at ændre oplysninger skal du indtaste dit kodeord!
</h6>
Nuværende Kode: <input type="password" class="form-control" placeholder="kodeord" name="password" required>
<hr>
Email: <input type="text" class="form-control" value="<% out.println(currUser.getEmail()); %>" name="email"> <br>
Brugernavn: <input type="text" class="form-control" value="<% out.println(currUser.getUsername()); %>" name="username"> <br>
<input type="submit" class="btn btn-default" value="Indsend Oplysninger" />
</form>
</div>
When importing JSP into JSP, it's important to know that they will conflict if 1. Duplicate Local Variables. 2. Certain HTML tags aren't correct.
Your intended use seems very complicated to me since I'm not quite understanding it, sorry :3 but if you can't get it working consider to throw it to a session and if it's a one time use then remove it once you used it.
This is working from dacades
<%# include file="../scripts/standard_head_declaration.jsp" %>
I have following code
JSP
<tbody>
<c:forEach var="defect" items="${defects}">
<tr>
<td>${defect.name}</td>
<td>${defect.description}</td>
<td>${defect.summary}</td>
<td>${defect.priority}</td>
<td>${defect.originator.name}</td>
<td>${defect.assignee.name}</td>
<td>
<form action="AllOpenDefects?defectId=${defect.id}" method="get">
<input type="submit" value="Update" />
</form>
</td>
</tr>
</c:forEach>
</tbody>
Servlet (in doGet method)
System.out.println((String) request.getParameter("defectId")); // It is printing null
and also in url the defectId is NOT been appended ... Is there any issue with my code?
EDIT: The url is http://localhost:8080/BugManagemetSystem/AllOpenDefects but it should be like http://localhost:8080/BugManagemetSystem/AllOpenDefects?defectId=2
It looks like your browser clears parameters after ?... in action="..." attribute. In that case try passing it via <input type="hidden" .../> like
<form action="AllOpenDefects" method="get">
<input type="hidden" name="defectId" value="${defect.id}"/>
<input type="submit" value="Update" />
</form>
This way form should add them to URL as ?defectId=value of ${defect.id}.
IMHO the short answer to your question is "your code is ok".
As a side note, if it doesn't yield the new required link, it's often an update problem. E.g. try changing the URL algtogether just for testing (form action="Junk"), see if the browser catches it.
If not, try clearing various caches - browser cache, deleting the exploded war and work directories (e.g. in Tomcat it's /webapps/myapp/ and /work)...
I am a Spring beginner and was recently looking at this tutorial
http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-annotation-example/
(There's a download link at the bottom of the page and with a quick maven install you should be able to run the project very easily.)
I noticed that when I pressed the submit button on the 1st page and it goes to the 2nd page, the URL stays the same. Now, I modified the 2nd page to have its own form. Unfortunately, because the URL is still the same on the 2nd page, Spring picks the controller for the 1st page when I click the 2nd page's submit button.
Why does this happen and how can I override this behavior?
Apologies if I am not being clear enough. Feel free to ask for certain clarification.
Thanks for your time
Regards
Steve
EDIT : My 2nd page's form looks like this
<form:form method="POST" commandName="step2">
<table width="800" align="center"
style="border-width: 5px; border-style: solid; border-color: gray;">
<caption>
<b>STEP 2</b>
</caption>
<tr>
<td></td>
<td colspan="3"><input type="submit" value="Submit Page 2"
cssClass="field" /></td>
</tr>
</table>
</form:form>
If you want the url to be updated when you navigage from Page1 to Page2 with Page2 url. Then use redirect on the server side instead of forward. I'm not how you do in Spring MVC, you may want to check Spring MVC reference manual.
I am implementing a search functionality in a website I am building, which involves searching by the md5 hash of the name of the file submitted and searching by the notes associated with each submitted file. So, I should detect as to which button is pressed "Search by MD5" or "Search by Notes". This is the code I have:
JSP code for the form:
<form id="search" name="search" action = "search.do"
method="POST" enctype="multipart/form-data">
<table align = "center">
<tr>
<th colspan="4" bgcolor="#004276"><font color="white">
Search for Sample
</th>
</tr>
<tr>
<td><input name="md5" type="text" value="${form.md5}"/></td>
<td><input name="md5search" type="submit" value="Search by MD5"/>
</tr>
<tr>
<td><input name="notes" type="text" value="${form.notes}"/></td>
<td><input name="notessearch" type="submit" value="Search by Notes"/>
</tr>
</table>
</form>
search.do is mapped to SearchResultsAction.java. Code in Java action class (SearchResultsAction) which handles the request is:
if(request.getParameter("md5search").toString().equals("Search by MD5")){
searchSubmissionsList = submissionsDAO.searchSubmissionsByMD5(form.getMD5());
}
if(request.getParameter("notessearch").toString().equals("Search by Notes")){
searchSubmissionsList = submissionsDAO.searchSubmissionByNotes(form.getNotes());
}
But the problem I am facing here is that, request.getParameter("md5search") and request.getParameter("notessearch") return null for some reason. I have been working on this for a while and have not been able to figure it out. The weird thing is that it once worked for me sometime back when I was working on another project. Am I missing something here?
It's null because you used multipart/form-data form encoding instead of (default) application/x-www-form-urlencoded. Basically, you have to (let Struts) extract the text fields from the multipart form data body the same way as you (or Struts) extracted the uploaded file. Or, as there is actually no <input type="file"> field in your form at all, just remove the enctype attribute altogether.
See also
Does form with enctype="multipart/form-data" cause problems accessing a hidden field