Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Refresh button problem with JSP and useBean  RSS feed

 
David Baranas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to accomplish something similar to the Tokenizer design pattern between a jsp page and the bean it is using. Basically the jsp page uses the bean to load in two pictures. Each picture is a form in the jsp page. When one of the images is submitted via the submit button the bean is used to register a vote and then relplace the two pics. I only want the pictures to update if a real vote has been submitted. If refresh is pressed I want the same thing to load up again.
How would I set-up a tokenizer pattern with the jsp and Bean file shown below? Thanks in advance for your help.
play.jsp
--------
<!--
-
- play.jsp
-
//-->
<%@ page errorPage="exceptionhandler.jsp" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="Razz" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/datetime-1.0" prefix="dt" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/dbtags" prefix="sql" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/request-1.0" prefix="req" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/session-1.0" prefix="sess" %>
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.0" prefix="str" %>
<jsp:useBean id="cart" scope="session" class="Razz" />
<jsp:setProperty name="cart" property="*" />
<%
cart.processRequest(request);
%>

<HTML><BODY>
the token = <jsp:getProperty name="cart" property="token"/>
<br>
the token1 =<jsp:getProperty name="cart" property="token1"/>
<br><br>
<form type=POST action=play.jsp>
<INPUT TYPE=hidden name="token" value="<str:randomString count="5" type="alphanumeric"/>">
<img src="<jsp:getProperty name="cart" property="v1"/>" width="200" height="200">
<INPUT TYPE=submit name="submit" value="play">
<form type=POST action=play.jsp>
<img src="<jsp:getProperty name="cart" property="v2"/>" width="200" height="200">
<INPUT TYPE=submit name="submit" value="play">
<br><br>
<sess:isNew>
This session is new.
</sess:isNew>
<sess:isNew value="false">
This session is not new.
</sess:isNew>
<br><br>
request.getParameter=<%=request.getParameter("id")%>
<br><br>
<sql:connection id="conn1" jndiName="ds1"/>
<%-- check if anything has been submitted --%>
<%
if(request.getParameter("id")!=null&&request.getParameter("id")!="") {
%>

<%
}
%>
<%-- print the rows in an HTML table --%>

<a href="test4.jsp">test4.jsp</a>
</BODY>
</HTML>
Razz.class
----------
import javax.servlet.http.*;
import java.sql.*;
public class Razz {
String v1 = null;
String v2 = null;
String submit = null;
String token = null;
String token1 = null;
String url = "jdbc:mysql://mysql/nethottie?user=nethottie&password=6x75z9";
public void setV1(String id) {
v1 = id;
}
public void setV2(String id) {
v2 = id;
}
public void setSubmit(String s) {
submit = s;
}
public void setToken(String t) {
token = t;
}
public void setToken1(String t) {
token1 = t;
}
public String getV1() {
return v1;
}
public String getV2() {
return v2;
}
public String getToken() {
return token;
}
public String getToken1() {
return token1;
}
public void processRequest(HttpServletRequest request) {
if (submit == null) {
v1 = "http://www.atpm.com/8.04/images/candy-legs.gif";
v2 = "http://www.atpm.com/8.04/images/candy-legs.gif";
}
else if (submit.equals("play")) {
Connection con;
Statement stmt;
try {
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url);
con.setAutoCommit(true);
stmt = con.createStatement();
ResultSet uprs = stmt.executeQuery("SELECT `*` FROM `people` ORDER BY RAND() LIMIT 2");
uprs.next();
v1 = uprs.getString("URL");
uprs.next();
v2 = uprs.getString("URL");
uprs.close();
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.println("-----SQLException-----");
System.err.println("SQLState: " + ex.getSQLState());
System.err.println("Message: " + ex.getMessage());
System.err.println("Vendor: " + ex.getErrorCode());
}
}
reset();
}
private void reset() {
submit = null;
token1 = token;
}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!