1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| package corej2me;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUtils;
import main.fctionalMatchar;
/**
* Servlet implementation class midletServlet
*/
public class MidletServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
// Get session information
HttpSession session = request.getSession(true);
// If a new session, we need to rewrite the URL for client
if (session.isNew())
{
// Get the URL that got us here
String incomingURL = HttpUtils.getRequestURL(request).toString();
// Encode by adding session ID onto URL
String URLwithID = response.encodeURL(incomingURL);
// Send back a header to client with new re-written URL
response.setHeader("Custom-newURL", URLwithID);
}
// Get the next score (parameter) passed in
int nextScore = Integer.parseInt(request.getParameter("score"));
// Get the ongoing total saved as part of the session
// Convert to an integer "object"
Integer sessionTotal = (Integer) session.getValue("sessionTotal");
// Running total from session and score passed in
int runningTotal = nextScore;
if (sessionTotal != null)
runningTotal += sessionTotal.intValue();
//******* reponse******************
/* */
// Update the session total, must save as an "object"
session.putValue("sessionTotal", new Integer(runningTotal));
String message ="jdbc:mysql://localhost:3306/";
try {
connect();
message += "100 ok";
} catch (Throwable t) {
message += "200 " + t.toString();
}
// Send back to client the new running total
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.write(Integer.toString(runningTotal));
out.close();
}
catch (Exception e)
{
System.err.println("Msg: " + e.toString());
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
doPost(request,response);
}
private void connect()
throws Exception {
fctionalMatchar fctionalmatchar = null;
fctionalmatchar = new fctionalMatchar();
fctionalmatchar.debutdescovery();//"C:/xampp/htdocs/queries/1.1/citycountry_hotel_service.owls");//sCurrentLine
// Establish a JDBC connection to the MYSQL database server.
//Class.forName("org.gjt.mm.mysql.Driver");
// Class.forName("com.mysql.jdbc.Driver").newInstance();
// Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,user,pwd);
} |
Partager