• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Browser back button

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have one main.jsp page which has some form fields and submit button.
on submit it goes to page called page2.jsp.
When user clicks on browser back button, getting warning as

Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.
To resubmit your information and view this Web page, click the Refresh button.
when I click on refresh it takes me to main.jsp page.
how to refresh and reload the page when user clicks Browser back button?
Thanks,
Padmashree
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi padma,
This may be related to setting the scope of the jsp page.u might have set the scope to 'request' .
try putting it to session.
i may be wrong also ???
Raj
 
padma patil
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajendra,
I am not using any Java beans where I can set the scope.
How I can set the scope to session in JSP?
-
padma
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have u given any no-cache instruction like this
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache>
or
set any response headers directing the browser not to cache the page.
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi padma,
If possible,can u send the code,so that can have a look at it ..
Raj
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi padma,
i just tried a simple jsp example ,by submitting a single field. iam able to get back to the main page by hitting the back button and is not throwing any exception.please take a look at this example. it got 2 files
test1.jsp
<html>
<body>
<form action="test2.jsp" method = "post">
Enter a name please <br><input type ="text" name ="t1">
<input type = "submit" value = "submit">
</form>
</html>
and test2.jsp

<html>
<%@ page session="true" %>
The Name u Entered is : 
<%String i = request.getParameter("t1");%>
<b><%= i%></b>
</html>
Raj
 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajendar,
My question is very similar to the above one.
I am getting the null pointer exception.can you please look into the code.
Error: 500
Location: /examples/jsp/myJsp/sayHello.jsp
Internal Servlet Error:
org.apache.jasper.JasperException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:200)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:148)
at jsp.myJsp.sayHello_2._jspService(sayHello_2.java:86)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Root cause:
java.lang.NullPointerException
at org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:162)
at org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:148)
at jsp.myJsp.sayHello_2._jspService(sayHello_2.java:86)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
sayHello.jsp
<%@ page import= "myJsp.name" %>
<jsp:useBean id="nameBean" class="myJsp.name" />
<jsp:setProperty name="inputName" property="*"/>
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "00ff00" text = "black">
<font size= 5>
Hello!! I am Pradnya.<p>
<form method=get>
What's your name? <input type=text name=inputName>
<input type = submit value="Submit">
</form>
<%
if ( request.getParameter("inputName") != null ) {
%>
<%@ include file="/jsp/myJsp/name2.jsp" %>
<%
}
%>
</font>
</body>
</html>
name2.jsp
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "yellow" text= "red">
<%@ page session="true" %>
<h2> Hello !!! <jsp:getProperty name="nameBean1" property="inputName" />!
Hope you'r enjoying this session.
</h2>
</body>
</html>
name.java (the bean)
package myJsp;
public class name
{

private String inputName;

public String getName()
{
return inputName;
}

public void setName(String name)
{
inputName = name;
}


}}
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The problem lies here
<jsp:getProperty name="nameBean1" property="inputName" />!
The name attribute is ="nameBean1" but where have u created the bean with that name using jsp:useBean tag? Unless u create an instance of the bean u cannot call jsp:getProperty tag.The property name should be "name" and not "inputName". The property name is decided based on setter and getter methods and not on the actual variable name declared in the bean. In ur case getName and setName so the property is "name".
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Trupti,
i hope u got what pradeep said,
u need to create an instance of a bean and for that ,the attribute which u mentioned in
<jsp:useBean id="nameBean" class="myJsp.name" />
must be similar to the 'name' attribute which u use in the 'get' and 'set' properties.
it shouldnt be
<jsp:getProperty name="nameBean1" property="inputName" />
but
<jsp:getProperty name="nameBean" property="inputName" />
.if u want u can take the example which i wrote ...

<html>
<head>
</head>
<%@page language='java'%>
<jsp:useBean id="userinfo" class="user.userinfo" scope="request" />
<jsp:setProperty name="userinfo" property="*" />
<body>
<table border=1>
<tr>
<td>Name </td>
<td>age</td>

</tr>
<tr>
<td><jsp:getProperty name ="userinfo" property="name" /></td>
<td><jsp:getProperty name ="userinfo" property="age" /></td>
</tr>
</table>
</body>
</html>
cheers,
Raj
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For property = "*" to work u need to use matching form field names .. if the property name in the bean is "name" ur text field name must also be "name" which is not the case in ur form.. plz change the text field name to "name"... and when u retrieve the property using jsp:getProperty pass "name" to property attribute.. Hope this helps! Good Luck
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have done the changes in my code as told by you.
like
in sayHello.java
%@ page import= "myJsp.name" %>
<jsp:useBean id="nameBean" class="myJsp.name" />
<jsp:setProperty name="name" property="*"/>
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "00ff00" text = "black">
<font size= 5>
Hello!! I am Pradnya.<p>
<form method= get>
What's your name? <input type=text name=name>
<input type = submit value="Submit">
</form>
<%
if (request.getParameter("name") != null ) {
%>
<%@ include file="/jsp/myJsp/name2.jsp" %>
in name2.jsp
<h2> Hello !!! <jsp:getProperty name = "nameBean" property="name"/>!
Hope you'r enjoying this session.
and the bean
private String inputName;

public String getName()
{
return inputName;
}

public void setName(String name)
{
inputName = name;
}

but still i am getting the null pointer exception.
I am using tomcat3.1.1
The first JSp appears correctly but when i enter the name instead of the second jsp page i am getting the above error.
Thanks,
Trupti
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trupti,
The ID attribute of the bean must be the same as the 'name' attribute u use in the get and set methods..
so it must be ,
<jsp:useBean id="nameBean" class="myJsp.name" />
<jsp:setProperty name="nameBean" property="*"/>
<jsp:getProperty name = "nameBean" property="name"/>
check this out and try compiling..
Raj
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the following code changes i am getting the following error..

error
Error: 500
Location: /examples/jsp/myJsp/sayHello.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Cannot find any information on property 'inputName' in a bean of type 'myJsp.Name'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:612)
at org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerator.java:101)
at org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(JspParseEventListener.java:792)
at org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventListener.java:221)
at org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseEventListener.java:176)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:210)
at org.apache.tomcat.facade.JasperLiaison.jsp2java(JspInterceptor.java:790)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:731)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
the sayHello.jsp
<%@ page import= "myJsp.Name" %>
<jsp:useBean id="nameBean" class="myJsp.Name" scope = "session" />
<jsp:setProperty name="inputName" property="*"/>
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "00ff00" text = "black">
<font size= 5>
Hello!! I am Pradnya.<p>
<form method= get>
What's your name? <input type=text name=yourName>
<input type = submit value="Submit">
</form>
<%
if (request.getParameter("yourName") != null ) {
%>
<%@ include file="/jsp/myJsp/name2.jsp" %>
<%
}
%>
the name2.jsp
<%@ page import= "myJsp.Name" %>
<jsp:useBean id="nameBean1" class="myJsp.Name" scope = "session" />
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "yellow" text= "red">
<h2> Hello !!! <jsp:getProperty name = "nameBean" property="inputName"/>!
Hope you'r enjoying this session.
</h2>
</body>
</html>
the bean name.java
package myJsp;
public class Name
{

private String yourName;

public String getName()
{
return yourName;
}

public void setName(String inputName)
{
yourName = inputName;
}


}

thanks,
Trupti
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trupti,
still the code seems to be confusing and unclear with the name attributes is concerned.

Here is the corrected code of ur actual code.please copy this and test it out....
<%@ page import= "myJsp.Name" %>
<jsp:useBean id="nameBean" class="myJsp.Name" scope = "session" />
<jsp:setProperty name="nameBean" property="*"/>
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "00ff00" text = "black">
<font size= 5>
Hello!! I am Pradnya.<p>
<form method= get>
What's your name? <input type=text name=yourName>
<input type = submit value="Submit">
</form>
<%
if (request.getParameter("yourName") != null ) {
%>
<%@ include file="/jsp/myJsp/name2.jsp" %>
<%
}
%>
the name2.jsp
<%@ page import= "myJsp.Name" %>
<jsp:useBean id="nameBean1" class="myJsp.Name" scope = "session" />
<html>
<head>
<title> My First JSP page.</title>
</head>
<body bgcolor = "yellow" text= "red">
<h2> Hello !!! <jsp:getProperty name = "nameBean1" property="inputName"/>!
Hope you'r enjoying this session.
</h2>
</body>
</html>
the bean name.java
package myJsp;
public class Name
{
private String yourName;
public String getName()
{
return yourName;
}
public void setName(String inputName)
{
yourName = inputName;
}

}
 
reply
    Bookmark Topic Watch Topic
  • New Topic