Resin is showing my app as active but I am getting 404 - java

as In topic my war is running without errors on Jetty / Tomcat but when I deploy it to the Resin 4
It shows as running / active in the deployed applications tab on the resin-admin panel. Nothing unusual in the logs as well.
But when I try to access myapp I am getting 404
Aug 14, 2013 9:20:25 AM com.caucho.server.cluster.Server start
INFO: resin.conf = null
Aug 14, 2013 9:20:25 AM com.caucho.server.cluster.Server start
INFO:
Aug 14, 2013 9:20:25 AM com.caucho.lifecycle.Lifecycle toActive
INFO: Host[] active
Aug 14, 2013 9:20:25 AM com.caucho.server.port.Port bind
INFO: http listening to *:8080
Aug 14, 2013 9:20:25 AM com.caucho.lifecycle.Lifecycle toActive
INFO: Server[id=,cluster=] active
Aug 14, 2013 9:20:25 AM com.caucho.server.resin.Resin start
INFO: Resin started in 2804ms
Aug 14, 2013 9:20:25 AM com.caucho.lifecycle.Lifecycle toStopping
INFO: Host[] stopping
Aug 14, 2013 9:20:25 AM com.caucho.lifecycle.Lifecycle toActive
INFO: Host[] active
Aug 14, 2013 9:20:26 AM com.caucho.lifecycle.Lifecycle toActive
INFO: WebApp[http://localhost:8080/myapp] active
web 3.0 app initializer
import com.opensymphony.sitemesh.webapp.SiteMeshFilter;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.Filter;
#Order(1)
public class AppWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{RootConfiguration.class};
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{WebConfiguration.class};
}
#Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
#Override
protected Filter[] getServletFilters() {
return new Filter[] { new SiteMeshFilter() };
}

Related

When submitting the form on the jsp page is running forever

When submitting the form on the jsp page below (cadastroPaciente.jsp), the System is running forever without returning any error.
I've already tested the connection alone in a Test Class and the Servlet without the connection to the database (only building the object and returning it to the screen) worked. But when I put it in the Servlet to save in the database it is running forever and does not save in database.
The buildpath has:
jakarta.servlet.jsp.jstl-api-2.0.0.jar
mysql-connector-java-8.0.26.jar
On the Console there's just this:
set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Server
version name: Apache Tomcat/9.0.39 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Server
built: Oct 6 2020 14:11:46 UTC set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Server
version number: 9.0.39.0 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: OS Name:
Windows 10 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: OS
Version: 10.0 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO:
Architecture: amd64 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Java Home:
C:\Program Files\Java\jdk-16.0.1 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: JVM
Version: 16.0.1+9-24 set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: JVM
Vendor: Oracle Corporation set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO:
CATALINA_BASE:
D:\Java\workspace-ee.metadata.plugins\org.eclipse.wst.server.core\tmp0
set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO:
CATALINA_HOME: D:\Java\Server\apache-tomcat-9.0.39 set. 09,
2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument:
-Dcatalina.base=D:\Java\workspace-ee.metadata.plugins\org.eclipse.wst.server.core\tmp0
set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Command
line argument: -Dcatalina.home=D:\Java\Server\apache-tomcat-9.0.39
set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Command
line argument:
-Dwtp.deploy=D:\Java\workspace-ee.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
set. 09, 2021 12:25:24 AM
org.apache.catalina.startup.VersionLoggerListener log INFO: Command
line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED set.
09, 2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener
log INFO: Command line argument:
--add-opens=java.base/java.io=ALL-UNNAMED set. 09, 2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log INFO: Command
line argument: --add-opens=java.base/java.util=ALL-UNNAMED set. 09,
2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument:
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED set. 09, 2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument:
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED set. 09, 2021 12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252 set. 09, 2021
12:25:24 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages
set. 09, 2021 12:25:24 AM
org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO:
Loaded Apache Tomcat Native library [1.2.25] using APR version
[1.7.0]. set. 09, 2021 12:25:24 AM
org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: APR
capabilities: IPv6 [true], sendfile [true], accept filters [false],
random [true]. set. 09, 2021 12:25:24 AM
org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO:
APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
set. 09, 2021 12:25:24 AM
org.apache.catalina.core.AprLifecycleListener initializeSSL INFO:
OpenSSL successfully initialized [OpenSSL 1.1.1g 21 Apr 2020] set.
09, 2021 12:25:25 AM org.apache.coyote.AbstractProtocol init INFO:
Initializing ProtocolHandler ["http-nio-8080"] set. 09, 2021 12:25:25
AM org.apache.catalina.startup.Catalina load INFO: Server
initialization in [565] milliseconds set. 09, 2021 12:25:25 AM
org.apache.catalina.core.StandardService startInternal INFO: Starting
service [Catalina] set. 09, 2021 12:25:25 AM
org.apache.catalina.core.StandardEngine startInternal INFO: Starting
Servlet engine: [Apache Tomcat/9.0.39] set. 09, 2021 12:25:25 AM
org.apache.coyote.AbstractProtocol start INFO: Starting
ProtocolHandler ["http-nio-8080"] set. 09, 2021 12:25:25 AM
org.apache.catalina.startup.Catalina start INFO: Server startup in
[687] milliseconds
Can someone help me?
JSP Page:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cadastro de Pacientes</title>
</head>
<body>
<form method="post" action="PacienteServlet">
<fieldset>
<legend>Dados do Paciente</legend>
<p>
<label for="cpf">CPF:</label>
<input type="text" size="14" id="cpf" name="cpf" />
</p>
<p>
<label for="nome">Nome:</label>
<input type="text" size="20" id="nome" name="nome" />
</p>
<p>
<label for="idade">Idade:</label>
<input type="number" size="3" id="idade" name="idade" />
</p>
<p>
<label for="telefone">Telefone:</label>
<input type="text" size="20" id="telefone" name="telefone" />
</p>
</fieldset>
<input type="submit" value="Enviar" />
</form>
</body>
</html>
JavaBeans:
package entity;
import java.io.Serializable;
public class Paciente implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String cpf;
private String nome;
private int idade;
private String telefone;
public Paciente(){}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
}
Servlet:
package servlet;
import entity.Paciente;
import persistence.PacienteDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
/**
* Servlet implementation class PacienteServlet
*/
#WebServlet("/PacienteServlet")
public class PacienteServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public PacienteServlet() {
super();
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.sendRedirect(response.encodeURL("cadastroPaciente.jsp"));
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Paciente paciente = new Paciente();
PacienteDao dao = new PacienteDao();
paciente.setCpf(request.getParameter("cpf"));
paciente.setNome(request.getParameter("nome"));
paciente.setIdade(Integer.parseInt(request.getParameter("idade")));
paciente.setTelefone(request.getParameter("telefone"));
dao.efetuarCadastro(paciente);
response.getWriter().append("Paciente cadastrado com sucesso!").append("<br />").append("<br />");
response.getWriter().append("CPF: "+paciente.getCpf()).append("<br />");
response.getWriter().append("Nome: "+paciente.getNome()).append("<br />");
response.getWriter().append("Idade: "+paciente.getIdade()).append("<br />");
response.getWriter().append("Telefone: "+paciente.getTelefone()).append("<br />").append("<br />");
response.getWriter().append(" Clique aqui para voltar para o formulário ");
} catch (SQLException e) {
request.setAttribute("error", e.toString());
RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
rd.forward(request, response);
} catch (Exception e) {
request.setAttribute("error", e.toString());
RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
rd.forward(request, response);
} finally {
out.close();
}
}
}
DAO:
package persistence;
import java.sql.*;
import javax.swing.JOptionPane;
public class Dao {
Connection con;
PreparedStatement stmt;
ResultSet rs;
CallableStatement call;
public void abrirConexao() throws Exception{
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/avaliacaojavaee", "root", "admin");
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
public void fecharConexao() throws Exception{
con.close();
}
}
DAO Child:
package persistence;
import java.util.ArrayList;
import java.util.List;
import entity.Paciente;
public class PacienteDao extends Dao {
public void efetuarCadastro(Paciente p) throws Exception {
abrirConexao();
stmt = con.prepareStatement("insert into paciente values(?,?,?,?)");
stmt.setString(1, p.getCpf());
stmt.setString(2, p.getNome());
stmt.setInt(3, p.getIdade());
stmt.setString(4, p.getTelefone());
stmt.execute();
stmt.close();
fecharConexao();
}
public List<Paciente> listaPacientes() {
try {
abrirConexao();
stmt = con.prepareStatement("select * from paciente");
rs = stmt.executeQuery();
List<Paciente> lista = new ArrayList<Paciente>();
while (rs.next()) {
Paciente p = new Paciente();
p.setCpf(rs.getString("cpf"));
p.setNome(rs.getString("nome"));
p.setIdade(rs.getInt("idade"));
p.setTelefone(rs.getString("tel"));
lista.add(p);
}
fecharConexao();
return lista;
} catch (Exception e) {
System.out.println(e.getMessage());
return null;
}
}
public Paciente mostraPaciente(String cpf) throws Exception {
abrirConexao();
stmt = con.prepareStatement("select * from paciente where cpf = ? ");
rs = stmt.executeQuery();
Paciente p = null;
if (rs.next()) {
p = new Paciente();
p.setCpf(rs.getString("cpf"));
p.setNome(rs.getString("nome"));
p.setIdade(rs.getInt("idade"));
p.setTelefone(rs.getString("telefone"));
}
fecharConexao();
return p;
}
}
I got it! It needed to include the mysql-connector-java-8.0.26.jar in the library (in the lib folder), below the WEB-INF. But thank you for the
DanielBarbarian because he pointed out an important subject about the JOptionPane. Actually my application is not a swing application so the JOptionPane doesn't make sense. This was because I copied it from somewhere else that was probably a Swing application.

spring mvc with angular 2 not working on eclipse, data is not getting loaded

I am tying to test a simple spring mvc with angular 2 project running on eclipse.
The html page is getting displayed, but it is not loading any data from spring backend, any idea why this is happening?
console output:
Oct 06, 2017 11:31:22 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:AngularjsSpringRestExample' did not find a matching property.
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.47
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Sep 29 2017 13:46:41 UTC
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.47.0
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_111\jre
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_111-b14
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\dzhao\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\dzhao\Downloads\apache-tomcat-8.0.47
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\dzhao\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\dzhao\Downloads\apache-tomcat-8.0.47
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\dzhao\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Users\dzhao\Downloads\apache-tomcat-8.0.47\endorsed
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Oct 06, 2017 11:31:22 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_111\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_131/bin/server;C:/Program Files/Java/jre1.8.0_131/bin;C:/Program Files/Java/jre1.8.0_131/lib/amd64;C:\Program Files (x86)\GnuWin32\bin\;C:\Program Files (x86)\RBTools\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\IBM\RationalSDLC\common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\bin;C:\Program Files (x86)\IBM\gsk8\lib;C:\Program Files (x86)\IBM\gsk8\bin;C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\RemoteClient\cteapis;C:\Program Files (x86)\Common Files\Check Point\UIFramework 3.0\Bin\;C:\Program Files (x86)\CheckPoint\Endpoint Security\Endpoint Common\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK\;C:\Users\dzhao\Java_Softwares\eclipse;;.
Oct 06, 2017 11:31:22 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Oct 06, 2017 11:31:22 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 06, 2017 11:31:22 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Oct 06, 2017 11:31:22 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Oct 06, 2017 11:31:22 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1209 ms
Oct 06, 2017 11:31:22 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 06, 2017 11:31:22 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.47
Oct 06, 2017 11:31:25 AM org.apache.jasper.servlet.TldScanner scanJars
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 TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Oct 06, 2017 11:31:25 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Oct 06, 2017 11:31:25 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'springrest'
Oct 06, 2017 11:31:25 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'springrest': initialization started
Oct 06, 2017 11:31:25 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'springrest-servlet': startup date [Fri Oct 06 11:31:25 EDT 2017]; root of context hierarchy
Oct 06, 2017 11:31:25 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/springrest-servlet.xml]
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/country/{id}],methods=[GET],produces=[application/json]}" onto public org.arpit.java2blog.bean.Country org.arpit.java2blog.controller.CountryController.getCountryById(int)
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/countries],methods=[POST],produces=[application/json]}" onto public org.arpit.java2blog.bean.Country org.arpit.java2blog.controller.CountryController.addCountry(org.arpit.java2blog.bean.Country)
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/countries],methods=[PUT],produces=[application/json]}" onto public org.arpit.java2blog.bean.Country org.arpit.java2blog.controller.CountryController.updateCountry(org.arpit.java2blog.bean.Country)
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/country/{id}],methods=[DELETE],produces=[application/json]}" onto public void org.arpit.java2blog.controller.CountryController.deleteCountry(int)
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/countries],methods=[GET],produces=[application/json]}" onto public java.util.List org.arpit.java2blog.controller.CountryController.getCountries()
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springrest-servlet': startup date [Fri Oct 06 11:31:25 EDT 2017]; root of context hierarchy
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springrest-servlet': startup date [Fri Oct 06 11:31:25 EDT 2017]; root of context hierarchy
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFO: Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
Oct 06, 2017 11:31:27 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'springrest': initialization completed in 2531 ms
Oct 06, 2017 11:31:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Oct 06, 2017 11:31:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Oct 06, 2017 11:31:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5321 ms
This is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.arpit.java2blog</groupId>
<artifactId>AngularjsSpringRestExample</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>AngularjsSpringRestExample Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>AngularjsSpringRestExample</finalName>
</build>
</project>
servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="org.arpit.java2blog.controller" />
<mvc:default-servlet-handler/>
</beans>
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
controller class:
package org.arpit.java2blog.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.arpit.java2blog.bean.Country;
import org.arpit.java2blog.service.CountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class CountryController {
#Autowired
private HttpServletRequest request;
CountryService countryService = new CountryService();
#RequestMapping(value = "/countries", method = RequestMethod.GET, headers = "Accept=application/json")
public List getCountries() {
List listOfCountries = countryService.getAllCountries();
return listOfCountries;
}
#RequestMapping(value = "/country/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
public Country getCountryById(#PathVariable int id) {
return countryService.getCountry(id);
}
#RequestMapping(value = "/countries", method = RequestMethod.POST, headers = "Accept=application/json")
public Country addCountry(#RequestBody Country country) {
return countryService.addCountry(country);
}
#RequestMapping(value = "/countries", method = RequestMethod.PUT, headers = "Accept=application/json")
public Country updateCountry(#RequestBody Country country) {
return countryService.updateCountry(country);
}
#RequestMapping(value = "/country/{id}", method = RequestMethod.DELETE, headers = "Accept=application/json")
public void deleteCountry(#PathVariable("id") int id) {
countryService.deleteCountry(id);
}
}
bean class:
package org.arpit.java2blog.bean;
public class Country{
int id;
String countryName;
long population;
public Country() {
super();
}
public Country(int i, String countryName,long population) {
super();
this.id = i;
this.countryName = countryName;
this.population=population;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public long getPopulation() {
return population;
}
public void setPopulation(long population) {
this.population = population;
}
}
service class:
package org.arpit.java2blog.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.arpit.java2blog.bean.Country;
/*
* It is just a helper class which should be replaced by database implementation.
* It is not very well written class, it is just used for demonstration.
*/
public class CountryService {
static HashMap<Integer,Country> countryIdMap=getCountryIdMap();
public CountryService() {
super();
if(countryIdMap==null)
{
countryIdMap=new HashMap<Integer,Country>();
// Creating some objects of Country while initializing
Country indiaCountry=new Country(1, "India",10000);
Country chinaCountry=new Country(4, "China",20000);
Country nepalCountry=new Country(3, "Nepal",8000);
Country bhutanCountry=new Country(2, "Bhutan",7000);
countryIdMap.put(1,indiaCountry);
countryIdMap.put(4,chinaCountry);
countryIdMap.put(3,nepalCountry);
countryIdMap.put(2,bhutanCountry);
}
}
public List getAllCountries()
{
List countries = new ArrayList(countryIdMap.values());
return countries;
}
public Country getCountry(int id)
{
Country country= countryIdMap.get(id);
return country;
}
public Country addCountry(Country country)
{
country.setId(getMaxId()+1);
countryIdMap.put(country.getId(), country);
return country;
}
public Country updateCountry(Country country)
{
if(country.getId()<=0)
return null;
countryIdMap.put(country.getId(), country);
return country;
}
public void deleteCountry(int id)
{
countryIdMap.remove(id);
}
public static HashMap<Integer, Country> getCountryIdMap() {
return countryIdMap;
}
// Utility method to get max id
public static int getMaxId()
{ int max=0;
for (int id:countryIdMap.keySet()) {
if(max<=id)
max=id;
}
return max;
}
}
html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<title>AngularJS $http Rest example</title>
<script type="text/javascript">
var app = angular.module("CountryManagement", []);
//Controller Part
app.controller("CountryController", function($scope, $http) {
$scope.countries = [];
$scope.countryForm = {
id : -1,
countryName : "",
population : ""
};
//Now load the data from server
_refreshCountryData();
//HTTP POST/PUT methods for add/edit country
// with the help of id, we are going to find out whether it is put or post operation
$scope.submitCountry = function() {
var method = "";
var url = "";
if ($scope.countryForm.id == -1) {
//Id is absent in form data, it is create new country operation
method = "POST";
url = '/AngularjsSpringRestExample/countries';
} else {
//Id is present in form data, it is edit country operation
method = "PUT";
url = '/AngularjsSpringRestExample/countries';
}
$http({
method : method,
url : url,
data : angular.toJson($scope.countryForm),
headers : {
'Content-Type' : 'application/json'
}
}).then( _success, _error );
};
//HTTP DELETE- delete country by Id
$scope.deleteCountry = function(country) {
$http({
method : 'DELETE',
url : '/AngularjsSpringRestExample/country/' + country.id
}).then(_success, _error);
};
// In case of edit, populate form fields and assign form.id with country id
$scope.editCountry = function(country) {
$scope.countryForm.countryName = country.countryName;
$scope.countryForm.population = country.population;
$scope.countryForm.id = country.id;
};
/* Private Methods */
//HTTP GET- get all countries collection
function _refreshCountryData() {
$http({
method : 'GET',
url : 'http://localhost:8080/AngularjsSpringRestExample/countries'
}).then(function successCallback(response) {
$scope.countries = response.data;
}, function errorCallback(response) {
console.log(response.statusText);
});
}
function _success(response) {
_refreshCountryData();
_clearFormData()
}
function _error(response) {
console.log(response.statusText);
}
//Clear the form
function _clearFormData() {
$scope.countryForm.id = -1;
$scope.countryForm.countryName = "";
$scope.countryForm.population = "";
};
});
</script>
<style>
.blue-button{
background: #25A6E1;
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#25A6E1',endColorstr='#188BC0',GradientType=0);
padding:3px 5px;
color:#fff;
font-family:'Helvetica Neue',sans-serif;
font-size:12px;
border-radius:2px;
-moz-border-radius:2px;
-webkit-border-radius:4px;
border:1px solid #1A87B9
}
.red-button{
background: #CD5C5C;
padding:3px 5px;
color:#fff;
font-family:'Helvetica Neue',sans-serif;
font-size:12px;
border-radius:2px;
-moz-border-radius:2px;
-webkit-border-radius:4px;
border:1px solid #CD5C5C
}
table {
font-family: "Helvetica Neue", Helvetica, sans-serif;
width: 50%;
}
caption {
text-align: left;
color: silver;
font-weight: bold;
text-transform: uppercase;
padding: 5px;
}
th {
background: SteelBlue;
color: white;
}
tbody tr:nth-child(even) {
background: WhiteSmoke;
}
tbody tr td:nth-child(2) {
text-align:center;
}
tbody tr td:nth-child(3),
tbody tr td:nth-child(4) {
text-align: center;
font-family: monospace;
}
tfoot {
background: SeaGreen;
color: white;
text-align: right;
}
tfoot tr th:last-child {
font-family: monospace;
}
td,th{
border: 1px solid gray;
width: 25%;
text-align: left;
padding: 5px 10px;
}
</style>
<head>
<body ng-app="CountryManagement" ng-controller="CountryController">
<h1>
AngularJS Restful web services example using $http
</h1>
<form ng-submit="submitCountry()">
<table>
<tr>
<th colspan="2">Add/Edit country</th>
</tr>
<tr>
<td>Country</td>
<td><input type="text" ng-model="countryForm.countryName" /></td>
</tr>
<tr>
<td>Population</td>
<td><input type="text" ng-model="countryForm.population" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" class="blue-button" /></td>
</tr>
</table>
</form>
<table>
<tr>
<th>CountryName</th>
<th>Population</th>
<th>Operations</th>
</tr>
<tr ng-repeat="country in countries">
<td> {{ country.countryName }}</td>
<td >{{ country.population }}</td>
<td><a ng-click="editCountry(country)" class="blue-button">Edit</a> | <a ng-click="deleteCountry(country)" class="red-button">Delete</a></td>
</tr>
</table>
</body>
</html>
If you want to return anything from a rest controller then you must use #ResponseBody annotation just before function declaration.
Like this in your case:
#RestController
public class CountryController {
#Autowired
private HttpServletRequest request;
CountryService countryService = new CountryService();
#RequestMapping(value = "/countries", method = RequestMethod.GET, headers = "Accept=application/json")
#ResponseBody
public List getCountries() {
List listOfCountries = countryService.getAllCountries();
return listOfCountries;
}
#RequestMapping(value = "/country/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
#ResponseBody
public Country getCountryById(#PathVariable int id) {
return countryService.getCountry(id);
}
.
.
.
}
And in case you are having a rest call which doesn't return anything then make sure to write #ResponseStatus(HttpStatus.NO_CONTENT)
Example:
#RequestMapping(value = "/country/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
#ResponseStatus(HttpStatus.NO_CONTENT)
public void setCountryById(#PathVariable int id) {
countryService.setCountry(id);
}

Spring annotation MVC return 404

I have built a Spring MVC skeleton Helloworld app that returns 404. here is the code:
Controller:
#Controller
#RequestMapping("/")
public class HelloWorldController {
#RequestMapping(value = {"/helloworld**"}, method = RequestMethod.GET)
public ModelAndView welcomePage() {
ModelAndView model = new ModelAndView();
model.setViewName("helloworld");
return model;
}
}
Config:
#Configuration
public class MvcWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{RootConfig.class};
}
#Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{ServletConfig.class};
}
#Override
protected String[] getServletMappings() { return new String[]{"/"}; }
}
#EnableWebMvc
#Configuration
#ComponentScan(basePackages = "com.tmlink.springmvc.controller.*")
public class RootConfig extends WebMvcConfigurerAdapter {
#Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver
= new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
#Configuration
public class ServletConfig extends WebMvcConfigurerAdapter {}
There is no XML config and helloworld.jsp is in WEB-INF/views/helloworld.jsp
When requesting http://localhost:8080/helloworld.jsp I get a 404.
The log from Tomcat at startup:
Jun 02, 2015 1:03:56 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jun 02, 2015 1:03:56 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Jun 02 13:03:56 CEST 2015]; root of context hierarchy
Jun 02, 2015 1:03:56 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
INFO: Registering annotated classes: [class com.tmlink.springmvc.springAdmin.RootConfig]
Jun 02, 2015 1:03:57 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: Root WebApplicationContext: startup date [Tue Jun 02 13:03:56 CEST 2015]; root of context hierarchy
Jun 02, 2015 1:03:57 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 924 ms
Jun 02, 2015 1:04:00 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [3,122] milliseconds.
Jun 02, 2015 1:04:00 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Jun 02, 2015 1:04:00 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Jun 02 13:04:00 CEST 2015]; parent: Root WebApplicationContext
Jun 02, 2015 1:04:00 PM org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
INFO: Registering annotated classes: [class com.xxxxx.springmvc.springAdmin.ServletConfig]
Jun 02, 2015 1:04:00 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 49 ms
Tomcat version: 7.0.56, Java version: 1.7.0.67.
Any idea what is wrong here?
Change to
#RequestMapping("/*")
Found the error:
#ComponentScan(basePackages = "com.tmlink.springmvc.controller.*")
should have been:
#ComponentScan(basePackages = "com.tmlink.springmvc.controller")
in RootConfig class.

Spring mvc Java based Configuration not working. Console display no error but my jsp page is not showing

Hello i am converting my simple demo project from bean configuration to pure java based configuration. Bean configuration works fine creating tables and all. But my java configuration is not displaying any pages. I solved many errors bur now console shows no error specifying the problem. here's my code please find whats wrong, or have i missed anything in the configuration. I am new to spring and fairly new to java based configuration. These are the sites from which i took code.
http://codehustler.org/blog/spring-security-tutorial-form-login-java-config/
for hibernate i use used this tutorial
http://websystique.com/spring/spring4-hibernate4-mysql-maven-integration-example-using-annotations/
My classes
1. AppConfiguration
package com.kharoud.configuration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
#Configuration
#ComponentScan({"com.kharoud"})
#Import({MvcConfiguraion.class, RepositoryConfiguration.class})
public class AppConfiguration {
}
2.MvcConfigurtion
package com.kharoud.configuration;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#EnableWebMvc
#Configuration
public class MvcConfiguraion extends WebMvcConfigurerAdapter{
#Override
public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer ){
configurer.enable();
}
#Bean
public InternalResourceViewResolver getInternalResourceViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views");
resolver.setSuffix(".jsp");
return resolver;
}
}
3.RepositoryConfiguration
package com.kharoud.configuration;
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
#Configuration
#EnableTransactionManagement
#PropertySource({ "classpath:hibernate.properties" })
public class RepositoryConfiguration {
#Autowired
private Environment environment;
#Bean
public LocalSessionFactoryBean sessionFactory(){
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] {"com.kharoud.model"});
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;
}
#Bean
public Properties hibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
return properties;
}
#Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
return dataSource;
}
#Bean
#Autowired
public HibernateTransactionManager transactionManager(SessionFactory s) {
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(s);
return txManager;
}
}
4.SpringConfigurationInitializer
package com.kharoud.configuration.initilizer;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import com.kharoud.configuration.AppConfiguration;
public class SpringConfigurationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
#Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppConfiguration.class };
}
#Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return null;
}
#Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
only added these new classes. I deleted my web.xml.
Later on i will add Spring Security configuration class
this is my console output
Feb 25, 2015 2:32:13 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_25\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Window s;C:/Program Files/Java/jre1.8.0_25/bin/server;C:/Program Files/Java/jre1.8.0_25/bin;C:/Program Files/Java/jre1.8.0_25/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\ system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShe ll\v1.0\;C:\Program Files\Java\jdk1.8.0_25\bin;;C:\ECLIPSE\eclipse;;.
Feb 25, 2015 2:32:14 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ProjectDemo' did not find a matching property.
Feb 25, 2015 2:32:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 25, 2015 2:32:14 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 25, 2015 2:32:14 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1063 ms
Feb 25, 2015 2:32:14 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 25, 2015 2:32:14 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Feb 25, 2015 2:32:15 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [217] milliseconds.
Feb 25, 2015 2:32:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [com.kharoud.configuration.initilizer.SpringConfigurationInitializer#389ae113]
Feb 25, 2015 2:32:18 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Feb 25, 2015 2:32:26 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Feb 25, 2015 2:32:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 25, 2015 2:32:26 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 25, 2015 2:32:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11876 ms
MyHomeController
package com.kharoud;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping("/")
public String welcome(Model model){
return "index";
}
}
Myindex.jsp file is in WEB-INF/views folder under webapp folder
The views were properly resolved with bean configuration.
Thank you for your answers. I found the problem. When i wrote #ComponentScan on top of my MvcConfiguration class it worked and pages are displaying.

Null point always

It all ways passing null point after this line, System.out.println("Inside the filter.............." ); so can anyone tell me what's wrong in my code and logic
and home.jsp(index page) did not display. here I want to filter every url and proceed only valid login users requests. here my logic..
UserServlet.java
private void loginDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
User u = new User();
UserService us =new UserServiceImpl() ;
String Uname = request.getParameter("txtUname");
String Pwrd = request.getParameter("txtPwrd");
u.setUname(Uname);
u.setPwrd(Pwrd);
System.out.println(Uname+""+Pwrd);
try {
if(us.Userlogin(u.getUname(),u.getPwrd())){
String message = "Thank you, " + Uname +"..You are now logged into the system";
request.setAttribute("message", message);
//RequestDispatcher rd = getServletContext().getRequestDispatcher("/menu.jsp");
//rd.forward(request, response);
HttpSession session = request.getSession(true);
session.setAttribute("loggedUser", u);
String reqUrl = (String)session.getAttribute("requestedURL");
session.removeAttribute("requestedURL");
response.sendRedirect(reqUrl);
}else{
// direct to login}
FilterRequest.java
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
System.out.println("Inside the filter.............." );
HttpSession session = request.getSession(true);
User u = null;
if(session.getAttribute("loggedUser")!=null){
u = (User) session.getAttribute("loggedUser");
}
if (u!= null)
{
System.out.println("user does exits.." + u.getUname() );
chain.doFilter(req, resp);
}else{
String message = "Please Login!";
req.setAttribute("loginMsg", message);
//response.sendRedirect("login2.jsp");
}
}
web.xml
<filter>
<filter-name>FilterRequest</filter-name>
<filter-class>com.mobitel.bankdemo.web.FilterRequest</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterRequest</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
stack trace
`Jul 11, 2013 10:24:26 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Workstations MP4\;C:\Program Files\Java\jdk1.6.0_07/bin;C:\Program Files\MySQL\MySQL Server 5.2\bin;D:\common libs\com.mysql.jdbc_5.1.5.jar;;C:\Users\lcladmin\Documents\Softwares\java related\eclipse-jee-indigo-win32_2\eclipse;
Jul 11, 2013 10:24:26 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:BankDemoWeb' did not find a matching property.
Jul 11, 2013 10:24:27 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 11, 2013 10:24:27 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 11, 2013 10:24:27 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 554 ms
Jul 11, 2013 10:24:27 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 11, 2013 10:24:27 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.41
Jul 11, 2013 10:24:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 11, 2013 10:24:27 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 11, 2013 10:24:27 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 517 ms
Inside the filter..............
user does exits..`
Thank you..
You have a real simple problem: The user is not logged in ;)
To clarify things:
In you Filter you're checking if the user is logged in and in this case execute the chain with
chain.doFilter(req, resp);
That's fine so far.
But what happens if the user is not logged in? In this case you're not executing the chain and therefore no Servlet. The Servlet is always the last element in the chain.
So your users cannot log in as they never get to the Servlet that allows them to log in as you filter them out before.
You have to extend your filter to allow logins when no user is logged in. This can be done e.g. by changing the url-pattern of the Filter.

Categories

Resources