I am trying to refresh the JSP page after certain operations, I am using DWR to be able to use my classes in Javascripts in the JSP files so I have this code:
function removeDN(numplanindex){
DBOps.removeDN(numplanindex);
relaod(true);
}
the above code will break the removeDN() and it would not refresh the page, I have also tried window.location.reload(true) and document.location.reload(true).
I am not sure about the difference as I barely know any Javascript but according to everything on google this should work. I am wondering if anybody know what is wrong with what I am doing wrong.
Thanks
It should be reload(true) instead of relaod(true)
Also see http://www.w3schools.com/jsref/met_loc_reload.asp
Related
I'm making a small web application using servlets and JSPS. (All the code will be shown in screenshots as the code keeps messing up when I try to put it in normally).
This is a snippet of the servlet class:
http://prntscr.com/irm32y
This is a snippet of the output JSP file:
http://prntscr.com/irm40z
And this is a snippet of the form JSP:
http://prntscr.com/irm4d7
For some reason, I'm not allowed to use the "polygon.digits" EL. I can only put numbers in there. (It's to specify how many decimals the user wants the answer to)
In my code I am trying to forward my request by using below line
<jsp:forward page = "<%=request.getContextPath()%>/Welcome.do"/>
However its giving error below
org.apache.jasper.JasperException: /obajsp/OBAHeader.jsp(3,27) JBWEB004214: Error unquoting attribute value
Please someone help me to understand what is issue in my written code?
EDIT:
this was currently working in production without any issue and giving issue in my local IDE
Have you tried using the expression language, rather than a scriptlet?
<jsp:forward page = "${pageContext.request.contextPath}/Welcome.do"/>
<jsp:forward page = "${pageContext.request.contextPath}/Welcome.do"/>
you dont need inline java to get the context path. expressionlanguage is much more comfortable.
I am fairly new in JSP and I am trying to figure out how to pass data entered in the form on a JSP page to the java class and send this data back to the JSP page on click.
My index.jsp looks a bit like this:
<%# page import="mypackage.*" %>
<% myClass c = new myClass();
c.setString("String"); %>
<p>This is a test: <%= c.getString(); %></p>
The above code will output "String". I can access my class with no problems if I set the value on page load. I tried using servlets after some research. I modified my form to add the servlet "testServlet" on form action:
<form method="POST" action="testServlet">
Then on the doPost() method in testServlet I added in this:
String myString = request.getParameter("myString"); //myString is also the name of my textbox
System.out.println("Entered string: " + myString);
However, I am clearly missing a crucial part of the flow of how this should work and I am most probably wrong with this one as well as all the form does after I press submit is redirect to testServlet so I get the error that the resource is not available since it isn't a JSP/html page.
So my questions are, how exactly can I pass data from JSP to java and vice versa? Also, is there a possible way to do this without servlets? And what are good tutorials/examples for studying JSP and its behavior such as passing data? Please help.
After some more research, I am now able to transfer data set on index to detail using jsp:useBean however, as I've read in all the forums I've visited, servlets should be used to handle this but this really confused me more as a beginner so I really want to figure out what I'm missing here.
I've made sure that the servlet is registered on web.xml and I didn't change anything in there.
Update: I've tried re-creating the project from scratch and somehow managed to make the servlet work. As it turns out, I was missing something on the doGet() method. But now my question stands, is there a way to process the form without using servlets or page import in the JSP file? I was shown a sample code that didn't use servlets or page imports. I did take notice at tag.
use the java beans with getters and setters for there class member variables.
i work on JSP and i want to call a java method(Function) on Click on a html button without using<script></script>.how?
i try to write this code:
<button onclick="<%po.killThread();%>">
<font size="4">Kill</font>
</button>
but it doesn't work... so please help me.
thanks
You're misunderstanding how server-side programming works. When you load that page, the webserver will get to the line <button onclick="<%po.killThread();%>"> and will immediately parse and execute the JSP snippet, in your case po.killThread(), and replace everything between the <% and %> with the return value of that method, if any. And all these happens on server side, before client receives any thing. (Note that this will only happen if that page is not already been loaded and compiled into a Servlet by the server.)
Thus, the HTML that client receives, will be something like, <button onclick="some return value or nothing">, which means that nothing will happen when you press the button. If you want to execute further JSP commands on the button press you will need to make a new request to the server - for example, by redirecting the page.
This will call the function killThread when you open the website.
Try to redirect to another jsp which calls the function.
this will not run at all because after the jsp page is compiled it will return the po.killThread() value but will not call this method
You can see this by viewing the page source
JSP is a server-side technology. Did I say server-side?
In order to understand how JSP works and to clear any misconception, JavaRanch Journal (Vol. 4, No. 2): The Secret Life of JavaServer Pages is a very good read.
An excerpt from the same,
JSP is a templating technology best-suited to the delivery of dynamic text documents in a format that is white-space agnostic.
Template text within a JSP page (which is anything that is not a dynamic element), to include all white-space and line terminators, becomes part of the final document.
All dynamic elements in a JSP are interpreted on the server and once the document is sent to the client, no further dynamic interaction is possible (short of requesting the same or another document).
If you are using JSPs, then to perform some method calles, you will have to write a servlet and then call the method in doPost or doGet method of servlet.
On the other hand, if you want to make things simpler, use JSF framework which will help you achieve your objective as JSF supports event handling.
I new in JSP, i have a problem with JSP
in php i use
$page=$_GET["page"]
for display multiple page for one layout it mean i have index , it display layout and when i click on menu go to about us the index url = index.jsp?page=about
in PHP when i declare $page above and next step i do
Switch($page){
case 1:about
include 'aboutus.php'
case 2:news
include 'news.php'
}
How can i do it ?
How jsp can do the same way php to display multiple page in 1 layout
Use jsp:include.
<jsp:include page="/WEB-INF/${param.page}.jsp" />
And pass ?page=news or ?page=about, etc as parameter. The ${param.page} prints the outcome of request.getParameter("page"). You can prevent direct access to JSP files (by entering URL in browser address bar) by placing JSP files in /WEB-INF folder.
See also:
Basic JSP/Servlet tutorials
Hidden features of JSP/Servlet
How to avoid Java code in JSP
nowadays you use "templates" of Java Server Faces (JSF) for this approach. When you use JSP, you actually don't use the same concept as in PHP. You'd better use the MVC concept. But to answer your question, you could probably achieve this with the include tag http://java.sun.com/products/jsp/tags/11/syntaxref1112.html and control it with JSTL:
http://www.java2s.com/Code/Java/JSTL/JSTLiftag.htm