Question
when I try to put my site to the server, it fails. Any help in tracking this down would be most appreciated. http://localhost:8080/webproject_Username_date/WEB-INF/classes/Myservlet.java MyservletDB.java import
when I try to put my site to the server, it fails.
Any help in tracking this down would be most appreciated.
http://localhost:8080/webproject_Username_date/WEB-INF/classes/Myservlet.java
MyservletDB.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/MyServletDB")
public class MyServletDB extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServletDB() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String keyword = request.getParameter("keyword");
search(keyword, response);
}
void search(String keyword, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Database Result";
String docType = " //
"transitional//en"> "; //
out.println(docType + //
" " + //
"
"
" + //"
" + title + "
");
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection.getConnection();
connection = DriverManager.getConnection(jdbc:mysql://localhost:8080.net:3306/myDB, newMysqlRemoteUser, mypassword);
if (keyword.isEmpty()) {
String selectSQL = "SELECT * FROM myTable";
preparedStatement = connection.prepareStatement(selectSQL);
} else {
String selectSQL = "SELECT * FROM myTable WHERE MYUSER LIKE ?";
String theUserName = keyword + "%";
preparedStatement =
connection.prepareStatement(selectSQL);
preparedStatement.setString(1, theUserName);
}
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
int id = rs.getInt("id");
String userName = rs.getString("myuser").trim();
String email = rs.getString("email").trim();
String phone = rs.getString("phone").trim();
if (keyword.isEmpty() || userName.contains(keyword)) {
out.println("ID: " + id + ", ");
out.println("User: " + userName + ", ");
out.println("Email: " + email + ", ");
out.println("Phone: " + phone + " ");
}
}
out.println("Search Data ");
out.println("");
rs.close();
preparedStatement.close();
connection.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (preparedStatement != null)
preparedStatement.close();
} catch (SQLException se2) {
}
try {
if (connection != null)
connection.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
----------------------------------------------------------------------------------------------------
MyServlet.java
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Myservlet {
static final boolean _W = System.getProperty("os.name").toLowerCase().contains("windows");
static String _PROP_FILENAME_WIN_LOCAL = "C:\YOUR_PATH\webproject\WebContent\config.properties";
static String _PROP_FILENAME_OSX_LOCAL = "/YOUR_PATH/webproject/WebContent/config.properties";
static String _PROP_FILENAME_REMOTE = "/var/lib/tomcat7/webapps/webproject/config.properties";
static Properties prop = new Properties();
public static void loadProperty() throws Exception {
FileInputStream inputStream = null;
if (_W) {
if (new File(_PROP_FILENAME_WIN_LOCAL).exists()) {
System.out.println("[DBG] Loaded: " + new File(_PROP_FILENAME_WIN_LOCAL).getAbsolutePath());
inputStream = new FileInputStream(_PROP_FILENAME_WIN_LOCAL);
}
} else {
if (new File(_PROP_FILENAME_OSX_LOCAL).exists()) {
System.out.println("[DBG] Loaded: " + new File(_PROP_FILENAME_OSX_LOCAL).getAbsolutePath());
inputStream = new FileInputStream(_PROP_FILENAME_OSX_LOCAL);
}
}
if (new File(_PROP_FILENAME_REMOTE).exists()) {
System.out.println("[DBG] Loaded: " + new File(_PROP_FILENAME_REMOTE).getAbsolutePath());
inputStream = new FileInputStream(_PROP_FILENAME_REMOTE);
}
if (inputStream == null) {
throw new FileNotFoundException();
}
prop.load(inputStream);
}
public static String getProp(String key) {
return prop.getProperty(key).trim();
}
}
Tomcat v7.0 Server at localhost [Apache Tomcat] Java/JavaVirtualMachines/jdk1.8.0 201.j tents/Home/bin/ja an 27, 2019, 4:00:59 PM Jan 27, 2019 4:01:01 PM org.apache. catalina.core.StandardService startInternal INFO: Starting service Catalina Jan 27, 2019 4:01:01 PM org.apache. catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.90 Jan 27, 2019 4:01:01 PM org.apache.catalina.startup.TldConfig execute INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no T Jan 27, 2019 4:01:01 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] Jan 27, 2019 4:01:01 PM org.apache. coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Jan 27, 2019 4:01:01 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 753 ms Jan 27, 2019 4:01:02 PM org.apache.catalina.core.StandardwrapperValve invoke SEVERE: Servlet.service) for servlet [MyServletDB] in context with path [/webproject java. lang.Error: Unresolved compilation problem: threw exception [Servlet execution threw an exception] Invalid character constant at MyServletDB. search(MyServletDB.java:43) at MyServletDB.doGet (My at javax.servlet.http.HttpServlet.service (HttpServlet.java: 624) at javax.servlet.http.HttpServlet.service (HttpServlet java:731) at org.apache.catalina.core.ApplicationFilterChain.internaLDoFilter( at org.apache.catalina. core. ApplicationFilterChain.doFilter(ApplicationFiiterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter( at org.apache.catalina.core.ApplicationFilterChain.internaLDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina. core.StandardwrapperValve.invoke (StandardwrapperValve.jav at org.apache.catalina.core.StandardContextValve.invoke( at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494) at org.apache.catalina.core.StandardHostValve.invoke(Stand at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.jav at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org .apache. coyote.http11.AbstractHttpilprocessor.process (AbstractHttp11Processorjava : 1136) at org.apache.coyote.AbstractProtocoL$AbstractConnectionHandler.process (AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor. run (JIoEndpoint.java:316) at java.util.concurrent. ThreadPoo LExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker. run (ThreadPoolExecutor.java: 624) at org.apache.tomcat.util.threads. TaskThread$WrappingRunnable. run TaskThread java:61) at java.lang. Thread. run (Thread.java: 748) tDB cationFi Chain 1136) at org.apache, tomote.AbstractProtoco lsAbstractconnectionhandStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started