This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP reloading error

 
Shuaib Gill
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a project which using JSP for presentation, Beans for business logic and Servlets for control and database connectivity. Now the JSP all have HTML forms in them, and per request, a specific servlet is called in the action element of a form.
I get through the project once with noe errors. When I try to view the project again, the second jsp page says Error: on the browser.
Why? It worked the first time, but when I try to go through the project to build a seperate query, it gives me and error.
I have to make a change in the JSP file, save it and hit reload, then it shows up again. But why doesn't it just show up the first time? I find myslef making simple changes to a JSP, saving it and hitting reload, why do I have to do it that way?
I am using Jrun 3.0 as a web server, and it is installed on my local machine, which as 128MB RAM.
Someone please help me fix this reloading error.
 
Trevor Dunn
Ranch Hand
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could be you have a caching problem. There a bunch of response headers you can set to turn it off, if it is your problem
Trevor
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error? (500 internal servlet error?) If so, check your servlet log file.

Open up the log file and examine what the real problem is. If it's a null pointer, re-examine all your servlet code. It is most likely not a 'coding' problem with the JSP's since they work the first time. The only way a JSP would work the first time, but blow up the second time, is that "in the meantime", your servlet has added or removed something from the session or application level, and when your JSP tries to get it, it gets null, and you haven't coded for this in your JSP.

Also, what do you mean 'the second page'... what is happening on this page? We need a few more details to help.
 
Shuaib Gill
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here is part of the first JSP...
// 1st JSP page
<%@ page language="java" contentType="text/html" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<html>
<head>
<title>Choose market</title>
</head>
<body bgcolor="white">
<%@ include file="header.html" %>
<%
response.addHeader("Pragma", "No-cache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
%>
<%! String sessionId=null; %>
<% HttpSession userSession = request.getSession(true); %>
<% sessionId = userSession.getId(); %>
<% userSession.setAttribute("id",sessionId); %>
<hr>
<h3>Choose a specific guide from the following</h3>
<table border=0>
<tr>
<td>
<form method="get" action="../servlet/WhichMarket">
<select name="market" size="5">
<br>
<option value="usa">US-2000
<option value="canada">CANADA-2000
<option value="mexico">Mexico
</select>
<br>
<input type="submit">
<input type="hidden" name="newSession" value="<%=sessionId %>">
</form>
</td>
<td>The options on the left determine which guide you will make description changes to.
In guide, you need to choose a specific market. Choose a market from the list on the left and hit Submit Query.
</td>
</tr>

</table>
<hr>
<%@ include file="footer.html" %>
</body>
</html>
When the user hits submit query, WhichMarket is called on the server.
// WhichMarket servlet
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import com.xxx.yyy.zzz.SomeBean;
public class WhichMarket extends HttpServlet
{
SomeBean notesData = null;
public void init() throws ServletException
{
//super.init(config);
notesData = new NotesBean();
getServletContext().setAttribute("notesData",notesData);
//req.setAttribute("notesData",notesData);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String userId = null;
String usaguide = null;
String canguide = null;
String mexguide = null;
String sessionId = null;
String userInput = req.getParameter("market");
String unique = req.getParameter("newSession");

String language ="/servlets/language.jsp";
try
{
if(userInput.equals("usa"))
{
int k=1;
usaCodeguide = "450011";
notesData.setGuide(k,usaCodeguide);
notesData.getCodeguide(k);
}
else if(userInput.equals("canada"))
{
int n=1;

canguide = "550012";

notesData.setGuide(n,canCodeguide);

notesData.getCodeguide(n);
}
else
{
int j=1;
mexguide = "27";

notesData.setCodeguide(j,mexCodeguide);
notesData.getCodeguide(j);
}


HttpSession session = req.getSession();
String uid = (String)session.getAttribute("id");

RequestDispatcher familydataRD = getServletContext().getRequestDispatcher("/servlets/language.jsp?userId=" + uid);
familydataRD.forward(req,res);
}
catch(Exception e)
{
out.println("Error: " + e.getMessage());
}
}// end doGet
}// end WhichMarket
This servlet passes a response to the 2nd JSP page, or language.jsp
<%@ page language="java" contentType="text/html" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="com.xxx.yyy.zzz.SomeBean"%>
<html>
<head>
<title>Choose language</title>
</head>
<body bgcolor="white">
<%@ include file="header.html" %>
<%! String sessionId=null; %>
<% HttpSession userSession = request.getSession(true); %>
<% String id = (String)session.getAttribute("id"); %>
<%
response.addHeader("Pragma", "No-cache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
%>
<jsp:useBean
id="notesData"
class="SomeBean"
scope="application">

</jsp:useBean>
<hr>
<h4>Choose a specific language and year for your query</h4>

<form method="get" action="../servlet/Query">

<select name="language" size="4">
<br>
<option value=1>ENGLISH
<option value=2>ENGLISH,CANADIAN
<option value=3>FRENCH
<option value=4>FRENCH,CANADIAN
<option value=5>GERMAN
<option value=6>ITALIAN
<option value=7>PORTUGESE, BRAZILIAN
<option value=8>SPANISH, CASTILIAN
<option value=9>SPANISH, MEXICAN
</select>

<%! int n=1; %>

<p>

<input type="hidden" name="marketCG" value="<%= notesData.getGuide(n)%>">
<input type="hidden" name="session" value="<%= id %>">
<input type="submit">

</form>

<a href="../servlets/market.jsp">
<img src="../servlets/back.gif" height=44 width=55 alt="previous page" border=0>
</a>

<hr>
<%@ include file="footer.html" %>
</body>
</html>
So, when I hit submit on the market.jsp, the request is processed by WhichMarket servlet and a response is passed to language.jsp. The language .jsp gives and Error message. The error says
Error: com.xxx.yyy.zzz.SomeBean
on the browser. Keep in mind, the first time I tried this it worked fine. I tried it a second time and this error showed up.
Hope you can provide some answers.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic