This is how far i have come trying to respond with a List<> of Users to a Client . Every time i get Error 500 so i tried to respond with just a String and it worked so there is not a problem with the server/client communication. I searched the Internet and i found some examples that they returned Lists<> without error but i can't get mine to work.
User Class
package org.cs131111.user;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "user")
public class User implements Serializable{
private String studentID;
private String Fname;
private String Lname;
private int semester;
public User(){}
public User(String sID,String fname,String lname,int sem){
this.studentID=sID;
this.Fname=fname;
this.Lname=lname;
this.semester = sem;
}
public String getId() {
return studentID;
}
#XmlElement
public void setId(String id) {
this.studentID = id;
}
public String getName() {
return Fname+"_"+Lname;
}
#XmlElement
public void setFName(String name) {
this.Fname = name;
}
#XmlElement
public void setLName(String name) {
this.Lname = name;
}
public int getSemester() {
return semester;
}
#XmlElement
public void setSemester(int semester) {
this.semester = semester;
}
}
UserList class
package org.cs131111.user;
import org.cs131111.db.DatabaseConnection;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class UserList {
public List<User> list = null;
public List<User> getAllUsers(){
User stud = null;
DatabaseConnection newc = null;
newc = new DatabaseConnection();
list = new ArrayList<User>();
try {
newc.results=newc.query.executeQuery("select * from `students`");
while(newc.results.next()){
stud = new User(newc.results.getString("studentid"),newc.results.getString("fname"),newc.results.getString("lname"),newc.results.getInt("semester"));
list.add(stud);
System.out.println(stud.getId()+" "+stud.getName());
}
} catch (SQLException ex) {
Logger.getLogger(UserList.class.getName()).log(Level.SEVERE, null, ex);
}
newc.close();
return list;
}
}
UserService class
package org.cs131111.user;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/UserService")
public class UserService {
UserList userOb = new UserList();
#GET
#Path("/users")
#Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
final List<User> users = userOb.getAllUsers();
return users;
}
}
The Client
<%#page import="java.util.List"%>
<%#page import="User.User"%>
<%#page import="java.io.IOException"%>
<%#page import="java.net.MalformedURLException"%>
<%#page import="java.io.InputStreamReader"%>
<%#page import="java.io.BufferedReader"%>
<%#page import="java.net.HttpURLConnection"%>
<%#page import="java.net.URL"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
try {
URL url = new URL("http://localhost:11118/EclassServer/webresources/UserService/users");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
List<User> u= (List<User>)conn.getContent();
out.println("Output from Server .... \n");
String test=u.get(1).getId();
out.println(test);
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
%>
</body>
</html>
Server's stack trace
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Failed : HTTP error code : 500
at org.apache.jsp.clientGet_jsp._jspService(clientGet_jsp.java:80)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
I can't post this as a comment so here it is. You can't really expect HttpUrlConnection.getContent to return a List of User instances. From the Javadoc
This method first determines the content type of the object by calling
the getContentType method. If this is the first time that the
application has seen that specific content type, a content handler for
that content type is created:
If the application has set up a content handler factory instance using
the setContentHandlerFactory method, the createContentHandler method
of that instance is called with the content type as an argument; the
result is a content handler for that content type. If no content
handler factory has yet been set up, or if the factory's
createContentHandler method returns null, then the application loads
the class named:
The usual way to get the content (when using HttpUrlConnection) is by using BufferedReader in combination with InputStreamReader something like
if(resCode==200){
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
stringBuilder = new StringBuilder();
String line=null;
while((line = reader.readLine()) != null){
stringBuilder.append(line + "\n");
}
}
But even now you will only get your User list as one large string (formatted as XML) and you should use an object mapper to convert the content/entity string to a List of User instances.
If, on the other hand, you used a Jersey client, it would be able to do the conversion automatically for you (it uses JAXB under the hood). Your Jersey client code might look something like (not tested)
WebTarget target = client.target(UriBuilder.fromUri("http://localhost:11118/EclassServer/webresources/UserService/users").build());
GenericType<List<User>> genType = new GenericType<List<User>>();
List<User> userList =(String) target.request().accept(MediaType.XML_APPLICATION).get(genType);
You don't have a correct root element. You've added the #XmlRootElement annotation to the User class, but it's not the root element as you're returning a list of users not a single user.
I recommend to specify a XSD and generate the JAXB classes rather than writing them yourself.
Related
I have this uni project going on, and I'm stuck on this error and can't find the solution.
First there's the JSP file that loads a list
<%#page import="Controllers.RestClient"%>
<%#page import="java.util.List"%>
<%#page import="Model.Stationss"%>
<%#page import="javax.xml.bind.JAXBException"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<label for="Origin">Embark Station:</label>
<select name ="StartStation" id="stations">
<%
List<Stationss> listS = RestClient.getStations();
for (int i = 0; i < listS.size(); i++) {
out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
}
%>
</select><br>
</body>
</html>
There's also the ReST client access
package Controllers;
import java.util.List;
import Model.Stationss;
import java.util.ArrayList;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBException;
public class RestClient {
public static List<Stationss> getStations() {
System.out.print("test");
String link = "http://localhost:8080";
String path = "/Service/webresources/pkg.service.stations";
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target(link).path(path);
Invocation.Builder invocation = target.request(MediaType.APPLICATION_XML);
System.out.print(link);
System.out.print(path);
Response response = invocation.get(Response.class);
System.out.print(response);
List<Stationss> list = response.readEntity(new GenericType<List<Stationss>>() {
});
System.out.print(list);
return list;
}
};
and after I have the model
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package Model;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Stationss {
private int id;
private String name;
private int zone;
Gate gates = new Gate(zone);
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getZone() {
return zone;
}
public void setZone(int zone) {
this.zone = zone;
}
public Gate getGates() {
return gates;
}
public void setGates(Gate gates) {
this.gates = gates;
}
public Stationss() {
}
public Stationss(int id, String name, int zone) {
this.id = id;
this.name = name;
this.zone = zone;
}
#Transient
public CheckTicket enter(String xml) {
return gates.enter(xml);
}
#Transient
public boolean exit(String xml) {
return gates.exit(xml);
}
}
and at last, the huge error screen
HTTP Status 500 – Internal Server Error
Type Exception Report
Message An exception occurred processing [/newjsp.jsp] at line [23]
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.apache.jasper.JasperException: An exception occurred processing [/newjsp.jsp] at line [23]
20: <label for="Origin">Embark Station:</label>
21: <select name ="StartStation" id="stations">
22: <%
23: List<Stationss> listS = RestClient.getStations();
24: for (int i = 0; i < listS.size(); i++) {
25: out.print("<option value = " + i + ">" + listS.get(i).getName() + "</option>");
26: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:610)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:499)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:359)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1444)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1252)
javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getStoredJaxbContext(AbstractJaxbProvider.java:288)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getJAXBContext(AbstractJaxbProvider.java:273)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:189)
org.glassfish.jersey.jaxb.internal.AbstractJaxbProvider.getUnmarshaller(AbstractJaxbProvider.java:164)
org.glassfish.jersey.jaxb.internal.AbstractCollectionJaxbProvider.readFrom(AbstractCollectionJaxbProvider.java:289)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:834)
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:363)
org.glassfish.jersey.client.InboundJaxrsResponse$2.call(InboundJaxrsResponse.java:126)
org.glassfish.jersey.internal.Errors.process(Errors.java:316)
org.glassfish.jersey.internal.Errors.process(Errors.java:298)
org.glassfish.jersey.internal.Errors.process(Errors.java:229)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:389)
org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:264)
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:123)
Controllers.RestClient.getStations(RestClient.java:36)
org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:143)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/10.0.16
It's my first time learning java and I'm completely at loss on what I'm doing wrong.
I know the link the xml list is working fine.
You have missing dependencies on your classpath
See the stack trace
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
This answer might be helpful
I'm trying to send variables between jsp and servlets, but I got this error that I still can't figure out why. It keeps sending HTTP Status 500 error.
it sending HTTP status 500 eror and java.lang.NullPointerException
but when i test java class in junit it ran fine.
this is jsp:
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page import="model.StudentDao"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Student</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<h1>Student</h1>
<table class="table">
<tr>
<th>Student ID</th>
<th>Student Name</th>
</tr>
<c:forEach items="${requestScope.students}" var="student">
<tr>
<td><c:out value="${student.getStudentId()}"/></td>
<td><c:out value="${student.getStudentName()}"/></td>
</tr>
</c:forEach>
</table>
</body>
</html>
and this my servlet:
package controller;
import...
#WebServlet("/StudentListServlet")
public class StudentListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public StudentListServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DbConnect dbConnect = new DbConnect();
Connection connection = dbConnect.connect();
StudentDao studentDao = new StudentDao(connection);
ArrayList<Student> students = null;
try {
students = studentDao.findAll();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("students", students);
request.getRequestDispatcher("student.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
StudentDao :
package model;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class StudentDao {
private Connection connection;
public StudentDao(Connection connection) {
super();
this.connection = connection;
}
public ArrayList<Student> findAll() throws SQLException{
ArrayList<Student> students = new ArrayList<>();
Student student = null;
Statement statement = this.connection.createStatement();
String sqlText = "SELECT * FROM student";
ResultSet resultSet = statement.executeQuery(sqlText);
while(resultSet.next()){
student = new Student();
student.setStudentId(resultSet.getString("student_Id"));
student.setStudentName(resultSet.getString("student_Name"));
students.add(student);
}
resultSet.close();
statement.close();
return students;
}
}
DbConnect:
package model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DbConnect {
private static final String URL = "jdbc:mysql://localhost:3306/university";
private static final String USER = "root";
private static final String PASSWORD = "";
private Connection connection;
public Connection connect() {
try {
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection(URL, USER, PASSWORD);
if(!this.connection.isClosed())
System.out.println("MySQL Connected");
else
System.out.println("MySQL Connect fail!");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return this.connection;
}
public void close() throws SQLException {
this.connection.close();
}
}
Stack Trace :
SEVERE: Servlet.service() for servlet [controller.StudentListServlet] in context with path [/MySQLDemo] threw exception
java.lang.NullPointerException
at model.StudentDao.findAll(StudentDao.java:21)
at controller.StudentListServlet.doGet(StudentListServlet.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Sorry for the long post.
anyone with an idea why this get error?
You are not loading the jdbc driver in your servelet
you can the jdbc driver as follows:
String driver = "com.mysql.jdbc.Driver";
// Load the JDBC driver
Class driver_class = Class.forName(driver);
So I'm starting a web application and I want to use JSP pages (I've used them before) to access dynamically to the database and retrieve data from different tables.
I have by now a basic DatabaseHelper class, an App class that only tests the DB helper connection and a simple query, and a jsp file. The problem I'm facing is that the Database connection works great if run from the App.java class, but if I run it from the JSP file it will throw a SQLException saying it didn't find a suitable driver. (I'll leave code and error message below)
I've tried different options I've read here in StackOverflow and other pages: I put the driver in the server's classpath, in the WEB-INF/lib, in the project's build path as external JAR (this one works for the Java app class mentioned before)...
And here is the environment:
Database: Microsoft SQL Server 2017
Driver: sqljdbc42.jar
Server: Glassfish 4.0
IDE: Eclipse Oxygen.3
So any hint on how can I solve this problem and use the Database helper from the jsp file will be happily welcome.
Thanks!
Error message:
[2018-03-28T12:39:48.883+0200] [glassfish 4.0] [SEVERE] [] [pl.mais.db.DBHelper] [tid: _ThreadID=21 _ThreadName=http-listener-1(3)] [timeMillis: 1522233588883] [levelValue: 1000] [[
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost;databaseName=campus_db;user=******;password=*****
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at pl.mais.db.DBHelper.open(DBHelper.java:41)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:58)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:748)
]]
App.java
package pl.mais.general;
import pl.mais.db.DBHelper;
public class App {
public static void main (String[] args) {
DBHelper db = new DBHelper();
db.open();
db.testSelectFaculties();
db.close();
}
}
DBHelper.java
package pl.mais.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* #author sergi
*
*/
public class DBHelper {
// JDBC driver name and database URL
private final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String DB_URL = "jdbc:sqlserver://localhost;databaseName=campus_db;";
// Database credentials
private static final String DB_USER = "*****";
private static final String DB_PASS = "*****";
private Connection conn = null;
private Statement stmt = null;
public DBHelper() {
try {
Class.forName(JDBC_DRIVER);
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
try {
String connectionUrl = DB_URL + "user=" + DB_USER + ";password=" + DB_PASS;
//System.out.println("Connecting to database...");
conn = DriverManager.getConnection(connectionUrl);
//System.out.println("Creating statement...");
stmt = conn.createStatement();
} catch (SQLException ex) {
Logger.getLogger(DBHelper.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void close() {
try {
stmt.close();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(DBHelper.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String[] testSelectFaculties() {
try {
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM faculties";
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
ArrayList<String> results = new ArrayList<String>();
// Iterate through the data in the result set and display it.
while (rs.next()) {
results.add(rs.getString(1) + " - " + rs.getString(2));
System.out.println(rs.getString(1) + " - " + rs.getString(2));
}
return (String[])results.toArray();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
index.jsp
<%#page import="pl.mais.db.DBHelper"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
DBHelper db = new DBHelper();
db.open();
String[] faculties = db.testSelectFaculties();
db.close();
for (int i = 0; i < faculties.length; i++) {
%>
<h2>
<%=
faculties[i]
%>
</h2>
<%
}
%>
</body>
</html>
Making the JDBC Driver JAR Files Accessible:
To integrate the JDBC driver into a GlassFish Server domain, copy the JAR files into the domain-dir/lib directory, then restart the server. This makes classes accessible to all applications or modules deployed on servers that share the same configuration.
Source: Oracle documentation.
in my Icefaces 3 application i have a drop down menu. I would like to populate it dynamicaly. In my ManagedBean i have a methode which define the menuItem. it get the label and actionMethod, and valued them on the MenuItem. When i launch my application, the item of drop down menu are always empty.
ManagedBean :
package com.omb.view;
import java.io.Serializable;
import javax.el.MethodExpression;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.icesoft.faces.component.menubar.MenuItem;
#Controller
#Scope("session")
public class MyBean implements Serializable {
private static final Log logger = LogFactory.getLog(MyBean.class);
private MenuItem menuItem1;
public String initMyBean() {
try {
initMenuItem();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
private void initMenuItem() {
menuItem1 = new MenuItem();
menuItem1.setValue("Menu 1");
MethodExpression actionExpression = FacesUtils.createAction("#{menu1Bean.display}", String.class);
menuItem1.setActionExpression(actionExpression);
}
public MenuItem getMenuItem1() {
return this.menuItem1;
}
public void setMenuItem1(MenuItem menuItem1) {
this.menuItem1 = menuItem1;
}
}
FaceUtils
package com.omb.view;
import javax.el.MethodExpression;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.MethodExpressionActionListener;
/**
* JSF utilities.
*/
public class FacesUtils {
public static MethodExpression createAction(String actionExpression, Class<?> returnType) {
FacesContext context = FacesContext.getCurrentInstance();
return context.getApplication().getExpressionFactory()
.createMethodExpression(context.getELContext(), actionExpression, returnType, new Class[0]);
}
public static MethodExpressionActionListener createActionListener(String actionListenerExpression) {
FacesContext context = FacesContext.getCurrentInstance();
return new MethodExpressionActionListener(context
.getApplication()
.getExpressionFactory()
.createMethodExpression(context.getELContext(), actionListenerExpression, null,
new Class[] {ActionEvent.class}));
}
}
screen.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<ui:composition>
<ice:form id="headerForm" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<div class="menu">
<ace:menuButton id="menuButton" effect="slide" effectDuration="200" value="Menu Button">
<ace:menuItem binding="#{myBean.menuItem1}"/>
</ace:menuButton>
</div>
</ice:form>
</ui:composition>
</body>
</html>
I finally use a the standard solution :
<ace:menuButton id="menuButton" effect="slide" effectDuration="200" value="Menu Button">
<ace:menuItem value="Menu 1" action="#{myBean.display}"/>
</ace:menuButton>
i´m following this tutorial Login and i´m facing some dificulties.
I have a MYSQL database, I created a table with id, username and password.
The database is up and running. Created an hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/timetable</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">k771u3</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>
<!-- mapping files -->
<mapping resource="User.hbm.xml" />
</session-factory>
</hibernate-configuration>
User.hbm.xml
<hibernate-mapping>
<class name="com.Logins.client.bean.User" table="username">
<id name="id" column="id" type="int" unsaved-value="null">
<generator class="native"/>
</id>
<property name="username" type="java.lang.String" column="username"/>
<property name="password" type="java.lang.String" column="password"/>
</class>
</hibernate-mapping>
Logins.java
package com.Logins.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.Logins.client.bean.User;
import com.Logins.client.screen.HomeScreen;
import com.Logins.client.screen.LoginScreen;
public class Logins implements EntryPoint {
private static Logins singleton;
public static Logins get(){
return singleton;
}
#Override
public void onModuleLoad() {
singleton=this;
setLoginScreen();
}
private void setLoginScreen() {
//Create the Login screen
LoginScreen scrLogin=new LoginScreen();
//Attach it to the root panel
RootPanel.get().add(scrLogin);
}
public void setHomeScreen(User user) {
HomeScreen homeScreen=new HomeScreen(user);
RootPanel.get().clear();
RootPanel.get().add(homeScreen);
}
}
GreetingService.java
package com.Logins.client;
import com.Logins.client.bean.User;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
public User checkLogin(String userName, String password);
public User isSessionAlive();
void logout();
}
GreetingServiceAsync.java
package com.Logins.client;
import com.Logins.client.bean.User;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface GreetingServiceAsync {
public void checkLogin(String userName, String password, AsyncCallback callback);
public void isSessionAlive(AsyncCallback callback);
public void logout(AsyncCallback callback);
}
HomeScreen.java
package com.Logins.client.screen;
import com.Logins.client.bean.User;
public class HomeScreen extends Composite{
public HomeScreen(User user) {
VerticalPanel vp=new VerticalPanel();
Label lblWelcome=new Label();
lblWelcome.setText("Hello "+user.getUserName());
vp.add(lblWelcome);
initWidget(vp);
}
}
LoginScreen.java
package com.Logins.client.screen;
import com.Logins.client.GreetingService;
public class LoginScreen extends Composite{
// TextBox for the User Name
private TextBox txtLogin=new TextBox();
// PasswordTextBox for the password
private PasswordTextBox txtPassword=new PasswordTextBox();
//Error Label
private Label lblError=new Label();
public LoginScreen() {
// Lets add a grid to hold all our widgets
Grid grid = new Grid(4, 2);
//Set the error label
grid.setWidget(0,1, lblError);
//Add the Label for the username
grid.setWidget(1,0, new Label("Username"));
//Add the UserName textBox
grid.setWidget(1,1, txtLogin);
//Add the label for password
grid.setWidget(2,0, new Label("Password"));
//Add the password widget
grid.setWidget(2,1, txtPassword);
//Create a button
Button btnLogin=new Button("login");
//Add the Login button to the form
grid.setWidget(3,1, btnLogin );
/*Add a click listener which is called
when the button is clicked */
btnLogin.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
checkLogin(txtLogin.getText(),txtPassword.getText());
}
});
initWidget(grid);
}
/*
* This method is called when the button is clicked
*/
private void checkLogin(String userName,String password) {
System.out.println("Checking login for "+userName);
/**
* Async call to the server to check for login
*/
AsyncCallback callback = new AsyncCallback() {
public void onSuccess(Object result) {
User user = (User) result;
if (user != null) {
setErrorText("");
// The user is authenticated, Set the home screen
Logins.get().setHomeScreen(user);
} else {
setErrorText("Invalid UserName or Password");
}
}
public void onFailure(Throwable ex) {
setErrorText("Error "+ex.getMessage());
}
};
getService().checkLogin(userName, password,callback);
}
private void setErrorText(String errorMessage) {
lblError.setText(errorMessage);
}
private GreetingServiceAsync getService() {
GreetingServiceAsync svc = (GreetingServiceAsync) GWT
.create(GreetingService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) svc;
endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "/GreetingService");
return svc;
}
}
GreetingServiceImpl.java
package com.Logins.server;
import javax.servlet.http.HttpSession;
import com.Logins.client.GreetingService;
import com.Logins.client.bean.User;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
private static final String USER_SESSION = "GWTAppUser";
private static final long serialVersionUID = 1;
private void setUserInSession(User user) {
HttpSession session = getThreadLocalRequest().getSession();
session.setAttribute(USER_SESSION, user);
}
private User getUserFromSession() {
HttpSession session = getThreadLocalRequest().getSession();
return (User) session.getAttribute(USER_SESSION);
}
public User checkLogin(String userName, String password) {
if (userName.equalsIgnoreCase("gwt")) {
User user = new User();
user.setUserName(userName);
setUserInSession(user);
return user;
} else
return null;
}
#Override
public void logout() {
HttpSession session = getThreadLocalRequest().getSession();
if (session != null)
session.invalidate();
}
#Override
public User isSessionAlive() {
User bean = getUserFromSession();
if ((bean != null) && (bean.getUserName().length() != 0)) {
System.out.println("User " + bean.getUserName()
+ " is already logged in");
return bean;
}
return null;
}
}
HibernateUtil
package util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
User.java
package com.Logins.client.bean;
import java.io.Serializable;
public class User implements Serializable{
/**
* Add this variable for serialization
*/
private static final long serialVersionUID = 1L;
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
When I 'Run As Web Application' appears the html form, but when i enter credentials, user and password, get this error:
Error 404 html head meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/ titleError 404 NOT_FOUND/title /head bodyh2HTTP ERROR: 404/h2preNOT_FOUND/pre pRequestURI=/logins//GreetingService/ppismalla href="http://jetty.mortbay.org/"Powered by Jetty:///a/small/i/pbr/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ br/ /body /html
If someone could help me figure out what is wrong or what remains to implement, would be very happy. It is very important to me. Thanks
Console Error:
Reloading web app to reflect changes in C:\Users\Martinho\Documents\SpringWorkSpace\Logins\war
[WARN] Server class 'com.google.gwt.dev.shell.jetty.JDBCUnloader' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/C:/springsource/sts-2.6.0.RELEASE/plugins/com.google.gwt.eclipse.sdkbundle_2.2.0.v201103311225/gwt-2.2.0/gwt-dev.jar' to the web app classpath for this session
For additional info see: file:/C:/springsource/sts-2.6.0.RELEASE/plugins/com.google.gwt.eclipse.sdkbundle_2.2.0.v201103311225/gwt-2.2.0/doc/helpInfo/webAppClassPath.html
Reload completed successfully
Checking login for
[WARN] 404 - POST /logins//GreetingService (127.0.0.1) 1409 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Referer: http://127.0.0.1:8888/Logins.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 161
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/logins/
X-GWT-Permutation: HostedMode
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.0 Safari/534.30
Content-Type: text/x-gwt-rpc; charset=UTF-8
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1409
Did you register your service in web.xml? It should contain something like
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaeeweb-app_2_5.xsd">
<servlet>
<servlet-name>greet</servlet-name>
<servlet-class>com.Logins.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greet</servlet-name>
<url-pattern>/greet</url-pattern>
</servlet-mapping>
</web-app>