问:
Generic type conversion
I'm having some serious design problems due to generics issues. Perhaps someone has some suggestions.

EDIT: So, I know this is not usually done, but I've completely changed my example code, because I've realized that the original pseudo-code did not really explain my problem. The following code much more closely resembles the real example I am dealing with. I hope that my problem will be clearer from it. I apologize ahead that it is a bit lengthy, but from my experience, problems with generics usually show up when you try to build a more complex structure. So:

```<code>class Program
    {
        static void Main(string[] args)
        {
            IConnector<IService> connector = ConnectorBuilderFactory.NewBuilder<IService>("someEndpoint").MakeReliable().GetConnector();
            connector.Connect();
        }
    }

    public interface IService : IConnectionMaintainable
    {
        void DoSomething();
    }

    public interface IConnectionMaintainable
    {
        DateTime GetServerTime();
    }

    public interface IConnector<T>
    {
        T Channel { get; }
        void Connect();
        void Disconnect();
    }

    public interface IConnectorBuilder<T>
    {
        IConnector<T> GetConnector();
        IConnectorBuilder<T> MakeReliable();
        // ...more connector-configuration methods
    }

    public class ChannelWatchDog<T> where T : IConnectionMaintainable
    {
        private IConnector<T> connector;

        public ChannelWatchDog(IConnector<T> connector /*various other parameters*/)
        {
            this.connector = connector;
        }

        // ...methods that use connector's Connect, Disconnect, and GetServerTime methods
    }

    public class Connector<T> : IConnector<T>
    {
        private T channel;

        public Connector(string endpoint)
        {
            // ...build channel
        }

        public T Channel
        {
            get { return channel; }
        }

        public void Connect()
        {
            // ...connect to server
        }

        public void Disconnect()
        {
            // ...disconnect from server
        }
    }

    public class ConnectorBuilder<T> : IConnectorBuilder<T>
    {
        private string endpoint;

        public ConnectorBuilder(string endpoint)
        {
            this.endpoint = endpoint;
        }

        public IConnector<T> GetConnector()
        {
            Connector<T> connector = new Connector<T>(endpoint);

            // If reliability was requested, build the ChannelWatchDog: Following line does not compile:
            // ChannelWatchDog<T> watchDog = new ChannelWatchDog<T>(connector);

            return connector;
        }

        public IConnectorBuilder<T> MakeReliable()
        {
            // save various parameters required to build the ChannelWatchDog
            return this;
        }
    }

    public static class ConnectorBuilderFactory
    {
        public static IConnectorBuilder<T> NewBuilder<T>(string endpoint)
        {
            return new ConnectorBuilder<T>(endpoint);
        }
    }
</code>```

So, firstly, if you find the GetConnector method in the ConnectorBuilder class, you will see the commented line of code, which does not compile if uncommented. This line is the essence of my problem. The problem might be obvious from the code, but I will try to explain it anyway in case it is not:

I have an internal class (ChannelWatchDog) that needs an IConnector. But not just any IConnector, an IConnector, because other than the non-generic IConnector methods, it also needs the GetServerTime method from the IConnectionMaintainable interface.

To simplify construction of connectors, I hoped to implement a builder using the Expression Builder pattern (the IConnectionBuilder interface). However, I want to be able to construct any IConnector, not just IConnector<IConnectionMaintainable>. Therefore, I cannot constrain T in IConnectorBuilder in the same way as I constrain it for the ChannelWatchDog. Lacking this constraint, I have no way to build it when GetConnector is called. Adding the constraint to the MakeReliable method does not help.

So, essentially the reason I posted this question was that I wanted to do something that is apparently impossible. I wanted the ChannelWatchDog and ConnectorBuilder class to look something like this:

```<code>public class ChannelWatchDog
    {
        private IConnector<IConnectionMaintainable> connector;

        public ChannelWatchDog(IConnector<IConnectionMaintainable> connector /*various other parameters*/)
        {
            this.connector = connector;
        }

        // ...methods that use connector's Connect, Disconnect, and GetServerTime methods
    }

    public class ConnectorBuilder<T> : IConnectorBuilder<T>
    {
        private string endpoint;

        public ConnectorBuilder(string endpoint)
        {
            this.endpoint = endpoint;
        }

        public IConnector<T> GetConnector()
        {
            Connector<T> connector = new Connector<T>(endpoint);

            // If reliability was requested, build the ChannelWatchDog: Following line does not compile:
            ChannelWatchDog watchDog = new ChannelWatchDog((IConnector<IConnectionMaintainable>)connector);

            return connector;
        }

        public IConnectorBuilder<TReliable> MakeReliable<TReliable>() where TReliable : T, IConnectionMaintainable
        {
            // save various parameters required to build the ChannelWatchDog
            return (IConnectorBuilder<TReliable>)this;
        }
    }
</code>```

But the cast to IConnector fails at runtime.

So that was much more lengthy than I had originally intended. If you've gotten this far in reading then you already have my thanks :)
Any ideas are welcome, including restructuring the code.

BTW, Having not found a solution to this myself, I created different ConnectorBuilders (in this case, a ReliableConnectorBuilder) and different factory methods in the factory. But I don't like this solution much.

EDIT: Just to clarify and reiterate: I cannot constrain the IConnector nor the ConnectionBuilder because these need to support cases in which the IConnectionMaintainable interface is not implemented.

答:
It is possible using reflection to allow casting the Connector<T> to Connector<IConnectionMaintainable>, I'm not sure how performance intensive this would be though and it requires being able to clone the Connector<T> class.

```<code>public class Connector<T> : IConnector<T>
{
    // ...
    private Connector()
    {
    }
    // ...
    public static explicit operator Connector<IConnectionMaintainable>(Connector<T> other)
    {
        Connector<IConnectionMaintainable> connector = null;

        Type p = typeof(T);
        if (p.GetInterfaces().Contains(typeof(IConnectionMaintainable)))
        {
            connector = new Connector<IConnectionMaintainable>();
            connector.channel = other.channel as IConnectionMaintainable;
        }
        else
        {
            throw new InvalidCastException();
        }

        return connector;
    }
}

public class ConnectorBuilder<T> : IConnectorBuilder<T>
{
    // ...
    public IConnector<T> GetConnector()
    {
        Connector<T> connector = new Connector<T>(endpoint);

        // If reliability was requested, build the ChannelWatchDog:
        try
        {
            Connector<IConnectionMaintainable> temp = (Connector<IConnectionMaintainable>)connector;
            ChannelWatchDog<IConnectionMaintainable> watchDog = new ChannelWatchDog<IConnectionMaintainable>(temp);
        }
        catch (InvalidCastException)
        {
            throw new ArgumentException("Trying to make reliable when not possible");
        }

        return connector;
    }
    // ...
}
</code>```

Title: Generic type conversion

Body:
I'm having some serious design problems due to generics issues. Perhaps someone has some suggestions.

EDIT: So, I know this is not usually done, but I've completely changed my example code, because I've realized that the original pseudo-code did not really explain my problem. The following code much more closely resembles the real example I am dealing with. I hope that my problem will be clearer from it. I apologize ahead that it is a bit lengthy, but from my experience, problems with generics usually show up when you try to build a more complex structure. So:

class Program
    {
        static void Main(string[] args)
        {
            IConnector<IService> connector = ConnectorBuilderFactory.NewBuilder<IService>("someEndpoint").MakeReliable().GetConnector();
            connector.Connect();
        }
    }

    public interface IService : IConnectionMaintainable
    {
        void DoSomething();
    }

    public interface IConnectionMaintainable
    {
        DateTime GetServerTime();
    }

    public interface IConnector<T>
    {
        T Channel { get; }
        void Connect();
        void Disconnect();
    }

    public interface IConnectorBuilder<T>
    {
        IConnector<T> GetConnector();
        IConnectorBuilder<T> MakeReliable();
        // ...more connector-configuration methods
    }

    public class ChannelWatchDog<T> where T : IConnectionMaintainable
    {
        private IConnector<T> connector;

        public ChannelWatchDog(IConnector<T> connector /*various other parameters*/)
        {
            this.connector = connector;
        }

        // ...methods that use connector's Connect, Disconnect, and GetServerTime methods
    }

    public class Connector<T> : IConnector<T>
    {
        private T channel;

        public Connector(string endpoint)
        {
            // ...build channel
        }

        public T Channel
        {
            get { return channel; }
        }

        public void Connect()
        {
            // ...connect to server
        }

        public void Disconnect()
        {
            // ...disconnect from server
        }
    }

    public class ConnectorBuilder<T> : IConnectorBuilder<T>
    {
        private string endpoint;

        public ConnectorBuilder(string endpoint)
        {
            this.endpoint = endpoint;
        }

        public IConnector<T> GetConnector()
        {
            Connector<T> connector = new Connector<T>(endpoint);

            // If reliability was requested, build the ChannelWatchDog: Following line does not compile:
            // ChannelWatchDog<T> watchDog = new ChannelWatchDog<T>(connector);

            return connector;
        }

        public IConnectorBuilder<T> MakeReliable()
        {
            // save various parameters required to build the ChannelWatchDog
            return this;
        }
    }

    public static class ConnectorBuilderFactory
    {
        public static IConnectorBuilder<T> NewBuilder<T>(string endpoint)
        {
            return new ConnectorBuilder<T>(endpoint);
        }
    }

So, firstly, if you find the GetConnector method in the ConnectorBuilder class, you will see the commented line of code, which does not compile if uncommented. This line is the essence of my problem. The problem might be obvious from the code, but I will try to explain it anyway in case it is not:

I have an internal class (ChannelWatchDog) that needs an IConnector. But not just any IConnector, an IConnector, because other than the non-generic IConnector methods, it also needs the GetServerTime method from the IConnectionMaintainable interface.

To simplify construction of connectors, I hoped to implement a builder using the Expression Builder pattern (the IConnectionBuilder interface). However, I want to be able to construct any IConnector, not just IConnector<IConnectionMaintainable>. Therefore, I cannot constrain T in IConnectorBuilder in the same way as I constrain it for the ChannelWatchDog. Lacking this constraint, I have no way to build it when GetConnector is called. Adding the constraint to the MakeReliable method does not help.

So, essentially the reason I posted this question was that I wanted to do something that is apparently impossible. I wanted the ChannelWatchDog and ConnectorBuilder class to look something like this:

public class ChannelWatchDog
    {
        private IConnector<IConnectionMaintainable> connector;

        public ChannelWatchDog(IConnector<IConnectionMaintainable> connector /*various other parameters*/)
        {
            this.connector = connector;
        }

        // ...methods that use connector's Connect, Disconnect, and GetServerTime methods
    }

    public class ConnectorBuilder<T> : IConnectorBuilder<T>
    {
        private string endpoint;

        public ConnectorBuilder(string endpoint)
        {
            this.endpoint = endpoint;
        }

        public IConnector<T> GetConnector()
        {
            Connector<T> connector = new Connector<T>(endpoint);

            // If reliability was requested, build the ChannelWatchDog: Following line does not compile:
            ChannelWatchDog watchDog = new ChannelWatchDog((IConnector<IConnectionMaintainable>)connector);

            return connector;
        }

        public IConnectorBuilder<TReliable> MakeReliable<TReliable>() where TReliable : T, IConnectionMaintainable
        {
            // save various parameters required to build the ChannelWatchDog
            return (IConnectorBuilder<TReliable>)this;
        }
    }

But the cast to IConnector fails at runtime.

So that was much more lengthy than I had originally intended. If you've gotten this far in reading then you already have my thanks :)
Any ideas are welcome, including restructuring the code.

BTW, Having not found a solution to this myself, I created different ConnectorBuilders (in this case, a ReliableConnectorBuilder) and different factory methods in the factory. But I don't like this solution much.

EDIT: Just to clarify and reiterate: I cannot constrain the IConnector nor the ConnectionBuilder because these need to support cases in which the IConnectionMaintainable interface is not implemented.

Body:
It is possible using reflection to allow casting the Connector<T> to Connector<IConnectionMaintainable>, I'm not sure how performance intensive this would be though and it requires being able to clone the Connector<T> class.

public class Connector<T> : IConnector<T>
{
    // ...
    private Connector()
    {
    }
    // ...
    public static explicit operator Connector<IConnectionMaintainable>(Connector<T> other)
    {
        Connector<IConnectionMaintainable> connector = null;

        Type p = typeof(T);
        if (p.GetInterfaces().Contains(typeof(IConnectionMaintainable)))
        {
            connector = new Connector<IConnectionMaintainable>();
            connector.channel = other.channel as IConnectionMaintainable;
        }
        else
        {
            throw new InvalidCastException();
        }

        return connector;
    }
}

public class ConnectorBuilder<T> : IConnectorBuilder<T>
{
    // ...
    public IConnector<T> GetConnector()
    {
        Connector<T> connector = new Connector<T>(endpoint);

        // If reliability was requested, build the ChannelWatchDog:
        try
        {
            Connector<IConnectionMaintainable> temp = (Connector<IConnectionMaintainable>)connector;
            ChannelWatchDog<IConnectionMaintainable> watchDog = new ChannelWatchDog<IConnectionMaintainable>(temp);
        }
        catch (InvalidCastException)
        {
            throw new ArgumentException("Trying to make reliable when not possible");
        }

        return connector;
    }
    // ...
}


来源: stackexchange

问:
Center image using margins
I'm having browser compatibility issues, in Chrome and Firefox when I use margin left and right to center and reduce image. Perfect, that's what I want. Buuuuut, only in the first image, the other images do not react the same way.

And in IE and Edge not even the first works as I wanted. The images just go right.

```<code><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Ski_trail_rating_symbol-blue_square.svg/600px-Ski_trail_rating_symbol-blue_square.svg.png" class="img-responsive center-block logo-index ng-scope" style="margin: 0 39%;">
<img src="http://s.cdpn.io/3/kiwi.svg" class="img-responsive center-block logo-index ng-scope" style="margin: 0 39%;">
<img src="https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="img-responsive center-block logo-index ng-scope" style="margin: 0 39%;">
</code>```

Codepen

Explanations of why this happens? (Yes, I know the solution is to use Width: Percentage. I was just curious.)

答:
Are you controlling the size of the images using margin?

img {
  display: block;
  margin: 0 auto;
}

.img1 {
  width: 100px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><img src="http://sismonitor.com.br/sismonitor/images/logo.svg" class="img1 img-responsive center-block logo-index ng-scope">

<img src="http://s.cdpn.io/3/kiwi.svg" class="img2 img-responsive center-block logo-index ng-scope">

<img src="https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="img3 img-responsive center-block logo-index ng-scope"></code>```

ContentLicense: CC BY-SA 3.0

Title: Center image using margins

Body:
I'm having browser compatibility issues, in Chrome and Firefox when I use margin left and right to center and reduce image. Perfect, that's what I want. Buuuuut, only in the first image, the other images do not react the same way.

And in IE and Edge not even the first works as I wanted. The images just go right.

Codepen

Explanations of why this happens? (Yes, I know the solution is to use Width: Percentage. I was just curious.)

Body:
Are you controlling the size of the images using margin?

img {
  display: block;
  margin: 0 auto;
}

.img1 {
  width: 100px;
}

<img src="http://sismonitor.com.br/sismonitor/images/logo.svg" class="img1 img-responsive center-block logo-index ng-scope">

<img src="http://s.cdpn.io/3/kiwi.svg" class="img2 img-responsive center-block logo-index ng-scope">

<img src="https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" class="img3 img-responsive center-block logo-index ng-scope">


问:
Expected session attribute error while using @SessionAtributes to add an entity object in session model?
I wanted to implement session using @SessionAttribute and add the user entity object to the session model to print the user details on the view page but i dont know there is an error. But if i just pass a string in a place of the user object the application works fine and the string is displaying on the view.

here is my controller

```<code>package com.mohit.Controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.mohit.beans.announcement;
import com.mohit.beans.users;
import com.mohit.Services.announceService;
import com.mohit.Services.createuser;

@Controller
@SessionAttributes("user")
public class UserController {

    @Autowired
    private createuser create;
    @Autowired
    private announceService announces;

    @RequestMapping("/")
    public String sayhi(){

        return "index";

    }

    @RequestMapping("/index")
    public String Createuser(@ModelAttribute("user") users user, Model
    model){

        int response=create.checkuser(user);
        if(response==1 || response==3)
            {
            Iterable<announcement> announce =announces.viewannounce();
            model.addAttribute("announce","announce");
            model.addAttribute("user","user");
            return "login";
            }
        else
            {
            model.addAttribute("invalid password","msg");
            return "index";
            }

    }
    @RequestMapping("/hii")
    public String AuthUser(Model model){

        return "index";

    }

}
</code>```

Entity class

```<code>package com.mohit.beans;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.springframework.transaction.annotation.Transactional;

@Entity
@Transactional
public class users {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    private String uname;
    private String pass;
    private String name;
    private byte year;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte getYear() {
        return year;
    }

    public void setYear(byte year) {
        this.year = year;
    }

    public users(String uname, String pass, String name, byte year) {
        super();

        this.uname = uname;
        this.pass = pass;
        this.name = name;
        this.year = year;
    }

    public users() {
        super();
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getUname() {
        return uname;
    }
    public void setUname(String uname) {
        this.uname = uname;
    }
    public String getPass() {
        return pass;
    }
    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public String toString() {
        return "users [id=" + id + ", uname=" + uname + ", pass=" + pass +
    ", name=" + name + ", year=" + year + "]";
    }

}
</code>```

Error stack ##

```  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-06-08 23:21:39.993  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : Starting LoanapimainApplication on MOHIT with PID 6828 (C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain\target\classes started by admin in C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain)
2017-06-08 23:21:40.004  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : No active profile set, falling back to default profiles: default
2017-06-08 23:21:40.365  INFO 6828 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@396c1e: startup date [Thu Jun 08 23:21:40 IST 2017]; root of context hierarchy
2017-06-08 23:21:42.302  INFO 6828 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-06-08 23:21:42.307  INFO 6828 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-06-08 23:21:42.323  INFO 6828 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-08 23:21:42.448  INFO 6828 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-06-08 23:21:42.463  INFO 6828 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2083 ms
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-08 23:21:43.213  INFO 6828 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-08 23:21:43.229  INFO 6828 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-06-08 23:21:43.307  INFO 6828 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-06-08 23:21:43.321  INFO 6828 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-06-08 23:21:43.321  INFO 6828 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-06-08 23:21:43.368  INFO 6828 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-06-08 23:21:43.555  INFO 6828 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-06-08 23:21:44.211  INFO 6828 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-08 23:21:44.696  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@396c1e: startup date [Thu Jun 08 23:21:40 IST 2017]; root of context hierarchy
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/announce]}" onto public java.lang.String com.mohit.Controllers.announceController.announce(com.mohit.beans.announcement,org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/index]}" onto public java.lang.String com.mohit.Controllers.UserController.Createuser(com.mohit.beans.users,org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hii]}" onto public java.lang.String com.mohit.Controllers.UserController.AuthUser(org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.mohit.Controllers.UserController.sayhi()
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-08 23:21:44.815  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:44.815  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:44.862  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:45.409  INFO 6828 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-06-08 23:21:45.456  INFO 6828 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-06-08 23:21:45.471  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : Started LoanapimainApplication in 5.931 seconds (JVM running for 6.474)
2017-06-08 23:21:53.285  INFO 6828 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-06-08 23:21:53.285  INFO 6828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2017-06-08 23:21:53.313  INFO 6828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms
2017-06-08 23:22:03.502 ERROR 6828 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Expected session attribute 'user'] with root cause

org.springframework.web.HttpSessionRequiredException: Expected session attribute 'user'
    at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:115) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:805) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_131]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]

2017-06-08 23:23:46.760 ERROR 6828 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Expected session attribute 'user'] with root cause

org.springframework.web.HttpSessionRequiredException: Expected session attribute 'user'
    at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:115) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:805) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_131]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]
```

<hr>

<h2>views</h2>

<hr>

```    <!DOCTYPE HTML>

    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Form

    <form action="/index"  method="post" modelAttribute="user">

user: <input type="text" name="uname"/>

password: <input type="text" name="pass" />

Welcome [[${name}]]

<input type="submit" value="Submit" /> <input type="reset" value="Reset" />

    </form>

----------
login.html

----------

    <!DOCTYPE HTML>

    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Welcome [[${user.name}]]

     <form action="/announce"  method="post" modelAttribute="announcement">

des: <input type="text" name="description"/>

link: <input type="text" name="link" />

first: <input type="text" name="first" />

sec: <input type="text" name="second" />

third: <input type="text" name="third" />

forth: <input type="text" name="forth" />

Staff: <input type="text" name="staff" />

sub: <input type="text" name="subject" />

<input type="submit" value="Submit" /> <input type="reset" value="Reset" />

    </form>

```

答:
You need to populate the form for the first time as it will be null. Add the following to your UserController:

```<code>@ModelAttribute("user")
public User populateForm() {
    return new User();
}
</code>```

Another note: make sure your Class names start with an uppercase, and your Method names start with lowercase. And remove @Transactional from your entity.

Body:
I wanted to implement session using @SessionAttribute and add the user entity object to the session model to print the user details on the view page but i dont know there is an error. But if i just pass a string in a place of the user object the application works fine and the string is displaying on the view.

here is my controller

package com.mohit.Controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.mohit.beans.announcement;
import com.mohit.beans.users;
import com.mohit.Services.announceService;
import com.mohit.Services.createuser;

@Controller
@SessionAttributes("user")
public class UserController {

    @Autowired
    private createuser create;
    @Autowired
    private announceService announces;

    @RequestMapping("/")
    public String sayhi(){

        return "index";

    }

    @RequestMapping("/index")
    public String Createuser(@ModelAttribute("user") users user, Model
    model){

        int response=create.checkuser(user);
        if(response==1 || response==3)
            {
            Iterable<announcement> announce =announces.viewannounce();
            model.addAttribute("announce","announce");
            model.addAttribute("user","user");
            return "login";
            }
        else
            {
            model.addAttribute("invalid password","msg");
            return "index";
            }

    }
    @RequestMapping("/hii")
    public String AuthUser(Model model){

        return "index";

    }

}

Entity class

package com.mohit.beans;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.springframework.transaction.annotation.Transactional;

@Entity
@Transactional
public class users {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    private String uname;
    private String pass;
    private String name;
    private byte year;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte getYear() {
        return year;
    }

    public void setYear(byte year) {
        this.year = year;
    }

    public users(String uname, String pass, String name, byte year) {
        super();

        this.uname = uname;
        this.pass = pass;
        this.name = name;
        this.year = year;
    }

    public users() {
        super();
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public String getUname() {
        return uname;
    }
    public void setUname(String uname) {
        this.uname = uname;
    }
    public String getPass() {
        return pass;
    }
    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public String toString() {
        return "users [id=" + id + ", uname=" + uname + ", pass=" + pass +
    ", name=" + name + ", year=" + year + "]";
    }

}

Error stack ##

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.3.RELEASE)

2017-06-08 23:21:39.993  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : Starting LoanapimainApplication on MOHIT with PID 6828 (C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain\target\classes started by admin in C:\Users\admin\Documents\workspace-sts-3.8.4.RELEASE\loanapimain)
2017-06-08 23:21:40.004  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : No active profile set, falling back to default profiles: default
2017-06-08 23:21:40.365  INFO 6828 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@396c1e: startup date [Thu Jun 08 23:21:40 IST 2017]; root of context hierarchy
2017-06-08 23:21:42.302  INFO 6828 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-06-08 23:21:42.307  INFO 6828 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-06-08 23:21:42.323  INFO 6828 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.14
2017-06-08 23:21:42.448  INFO 6828 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-06-08 23:21:42.463  INFO 6828 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2083 ms
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-06-08 23:21:42.620  INFO 6828 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-06-08 23:21:43.213  INFO 6828 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2017-06-08 23:21:43.229  INFO 6828 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2017-06-08 23:21:43.307  INFO 6828 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2017-06-08 23:21:43.321  INFO 6828 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2017-06-08 23:21:43.321  INFO 6828 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2017-06-08 23:21:43.368  INFO 6828 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2017-06-08 23:21:43.555  INFO 6828 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2017-06-08 23:21:44.211  INFO 6828 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-06-08 23:21:44.696  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@396c1e: startup date [Thu Jun 08 23:21:40 IST 2017]; root of context hierarchy
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/announce]}" onto public java.lang.String com.mohit.Controllers.announceController.announce(com.mohit.beans.announcement,org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/index]}" onto public java.lang.String com.mohit.Controllers.UserController.Createuser(com.mohit.beans.users,org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hii]}" onto public java.lang.String com.mohit.Controllers.UserController.AuthUser(org.springframework.ui.Model)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public java.lang.String com.mohit.Controllers.UserController.sayhi()
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-06-08 23:21:44.784  INFO 6828 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-06-08 23:21:44.815  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:44.815  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:44.862  INFO 6828 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-06-08 23:21:45.409  INFO 6828 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-06-08 23:21:45.456  INFO 6828 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-06-08 23:21:45.471  INFO 6828 --- [           main] com.mohit.LoanapimainApplication         : Started LoanapimainApplication in 5.931 seconds (JVM running for 6.474)
2017-06-08 23:21:53.285  INFO 6828 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-06-08 23:21:53.285  INFO 6828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2017-06-08 23:21:53.313  INFO 6828 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms
2017-06-08 23:22:03.502 ERROR 6828 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Expected session attribute 'user'] with root cause

org.springframework.web.HttpSessionRequiredException: Expected session attribute 'user'
    at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:115) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:805) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_131]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]

2017-06-08 23:23:46.760 ERROR 6828 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Expected session attribute 'user'] with root cause

org.springframework.web.HttpSessionRequiredException: Expected session attribute 'user'
    at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:115) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:805) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_131]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.14.jar:8.5.14]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_131]

views

    <!DOCTYPE HTML>

    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Form

    <form action="/index"  method="post" modelAttribute="user">

user: <input type="text" name="uname"/>

password: <input type="text" name="pass" />

Welcome [[${name}]]

<input type="submit" value="Submit" /> <input type="reset" value="Reset" />

    </form>

----------
login.html

----------

    <!DOCTYPE HTML>

    <title>Getting Started: Handling Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Welcome [[${user.name}]]

     <form action="/announce"  method="post" modelAttribute="announcement">

des: <input type="text" name="description"/>

link: <input type="text" name="link" />

first: <input type="text" name="first" />

sec: <input type="text" name="second" />

third: <input type="text" name="third" />

forth: <input type="text" name="forth" />

Staff: <input type="text" name="staff" />

sub: <input type="text" name="subject" />

<input type="submit" value="Submit" /> <input type="reset" value="Reset" />

    </form>

Body:
You need to populate the form for the first time as it will be null. Add the following to your UserController:

@ModelAttribute("user")
public User populateForm() {
    return new User();
}

Another note: make sure your Class names start with an uppercase, and your Method names start with lowercase. And remove @Transactional from your entity.


问:
Declare a namespace inside Policy in API Management Service
I am working on API Management service. I want to set Authorization Header in API.
I have used Set-Header policy & in Value tag, I need to generate Microsoft.IdentityModel.Clients.ActiveDirectory Authentication object.
But I am not able to add Microsoft.IdentityModel.Clients.ActiveDirectory namespace inside the policy.
I need to make sure is this possible to add Microsoft.IdentityModel.Clients.ActiveDirectory namespace inside Policy Expression?

答: No, policy expressions allow a subset of .NET Framework.</p>


问:
Joining two tables and retrieving records from new table in Mysql
I have two tables student(crn,age,name) and account(crn,account_id,fee). I want to get account_id of students whose age is less than 20. How can i do that in MySQL?</p>

答:
```<code>SELECT account_id, name, age
FROM student s inner join account a on s.crn = a.crn
where age < 20
</code>```


问:
How to remove value from Multidimensional Array based on Key and Value - PHP
How can I remove value "288" from "pecan" and return the updated array.

Array like so:

```<code>a: 10: {
s: 13: "Fraser Island";
a: 7: {
    i: 0;
    i: 303;
    i: 1;
    i: 34;
    i: 2;
    i: 27;
    i: 3;
    i: 291;
    i: 4;
    i: 293;
    i: 5;
    i: 37;
    i: 6;
    i: 288;
}
s: 5: "pecan";
a: 5: {
    i: 0;
    i: 34;
    i: 1;
    i: 27;
    i: 2;
    i: 291;
    i: 3;
    i: 59;
    i: 4;
    i: 288;
}
s: 11: "New Triper";
a: 3: {
    i: 0;
    i: 291;
    i: 1;
    i: 293;
    i: 2;
    i: 288;
}
</code>```

}

Which translates to this in PHP:

```<code>Array (
[0] => Array (
    [Fraser Island] => Array (
        [0] => 303
        [1] => 34
        [2] => 27
        [3] => 291
        [4] => 293
        [5] => 37
        [6] => 288
    )
    [pecan] => Array (
        [0] => 34
        [1] => 27
        [2] => 291
        [3] => 59
        [4] => 288
    )
    [New Triper!] => Array (
        [0] => 291
        [1] => 293
        [2] => 288
    )
)
</code>```

)

Delete/remove a value from a multidimensional array by finding the array column name and the value. I use this code:

```<code>// DELETE VALUE FROM ARRAY
function remove_element_by_value($arr, $val) {
    $return = array();
    foreach($arr as $k => $v) {
        if(is_array($v)) {
            $return[$k] = remove_element_by_value($v, $val); //recursion
            continue;
        }
        if($v == $val) continue;
            $return[$k] = $v;
        }
   return $return;
}
</code>```

However it removes all matching values from all array columns.

答:
```<code>// DELETE VALUE FROM ARRAY
function remove_element_by_value($arr, $key ,$val ) {
    $return = array();
    foreach($arr as $k => $v) {
        if(is_array($v)) {
            $return[$k] = remove_element_by_value($v, $val); //recursion
            continue;
        }
        if($v == $val && $k == $key) continue;
            $return[$k] = $v;
        }
   return $return;
}
</code>```

Body:
How can I remove value "288" from "pecan" and return the updated array.

Array like so:

a: 10: {
s: 13: "Fraser Island";
a: 7: {
    i: 0;
    i: 303;
    i: 1;
    i: 34;
    i: 2;
    i: 27;
    i: 3;
    i: 291;
    i: 4;
    i: 293;
    i: 5;
    i: 37;
    i: 6;
    i: 288;
}
s: 5: "pecan";
a: 5: {
    i: 0;
    i: 34;
    i: 1;
    i: 27;
    i: 2;
    i: 291;
    i: 3;
    i: 59;
    i: 4;
    i: 288;
}
s: 11: "New Triper";
a: 3: {
    i: 0;
    i: 291;
    i: 1;
    i: 293;
    i: 2;
    i: 288;
}

}

Which translates to this in PHP:

Array (
[0] => Array (
    [Fraser Island] => Array (
        [0] => 303
        [1] => 34
        [2] => 27
        [3] => 291
        [4] => 293
        [5] => 37
        [6] => 288
    )
    [pecan] => Array (
        [0] => 34
        [1] => 27
        [2] => 291
        [3] => 59
        [4] => 288
    )
    [New Triper!] => Array (
        [0] => 291
        [1] => 293
        [2] => 288
    )
)

)

Delete/remove a value from a multidimensional array by finding the array column name and the value. I use this code:

// DELETE VALUE FROM ARRAY
function remove_element_by_value($arr, $val) {
    $return = array();
    foreach($arr as $k => $v) {
        if(is_array($v)) {
            $return[$k] = remove_element_by_value($v, $val); //recursion
            continue;
        }
        if($v == $val) continue;
            $return[$k] = $v;
        }
   return $return;
}

However it removes all matching values from all array columns.


问:
dropzone.js is not working inside angularjs partial view
Dropzone js is an awesome plugin used for drag & drop upload. I want it to implement in my angularjs project.

Please find the scenario, which I have tried

I have included

```<code><form id="my-awesome-dropzone" action="/target" class="dropzone"></form>
</code>```

inside partial view, while executing the page in browser  tag itself removed from DOM.

When I include it in index.html page, it is working properly. Please let me know how to make dropzone working, inside angularjs partial view.

答:
You mentioned that you included:

```<code><form id="my-awesome-dropzone" action="/target" class="dropzone"></form>
</code>```

The issue may simply be that you included the above form "inside" another form.

Body:
Dropzone js is an awesome plugin used for drag & drop upload. I want it to implement in my angularjs project.

Please find the scenario, which I have tried

I have included

<form id="my-awesome-dropzone" action="/target" class="dropzone"></form>

inside partial view, while executing the page in browser  tag itself removed from DOM.

When I include it in index.html page, it is working properly. Please let me know how to make dropzone working, inside angularjs partial view.

Body:
You mentioned that you included:

<form id="my-awesome-dropzone" action="/target" class="dropzone"></form>

The issue may simply be that you included the above form "inside" another form.


问:
Why doesn't this SQL statement work?
```
SELECT * FROM table1, table2
WHERE table1.user_id = table2.id
AND table1.content = news
AND table1.content_id = 1
```

that wont work. cant u have two "AND" in a sql statement??

//Tomek

答:
you probably want to quote 'news' as a string...
You also probably want to use an inner join instead (much more efficient)</p>

```<code>SELECT * FROM table1
INNER JOIN table2 ON table1.user_id = table2.id
WHERE table1.content = 'news'
AND table1.content_id = 1
</code>```

OwnerDisplayName: Tomek

LastEditorDisplayName: Graeme Perrow

ContentLicense: CC BY-SA 2.5

Title: Why doesn't this SQL statement work?

Body:
SELECT * FROM table1, table2
WHERE table1.user_id = table2.id
AND table1.content = news
AND table1.content_id = 1

that wont work. cant u have two "AND" in a sql statement??

//Tomek

Body:
you probably want to quote 'news' as a string...
You also probably want to use an inner join instead (much more efficient)

SELECT * FROM table1
INNER JOIN table2 ON table1.user_id = table2.id
WHERE table1.content = 'news'
AND table1.content_id = 1


问:
Dataweave empty array input add default key:value
is there a way to map a http response which is in json array to another json map also considering default values i.e when it is empty map a default key pair?

input

```<code>{

"key1": []
"key2":[x,y]
}
</code>```

req output

```<code>{"table":[{
  "a-key1": "deafault-value",
  "a-key2": "x",
  "b-key2": "y"
  }]
}
</code>```

答:
```<code><dw:transform-message doc:name="Transform Message" metadata:id="....">
<dw:input-payload mimeType="application/xml"/>
<dw:set-payload>
<![CDATA[%dw 1.0
%output application/xml
---
{
    table: {
        (payload.*object map ( {
            key: $.value when $.value != empty
                 otherwise 'deafault-value'
        }))
    }
}
]]>
</dw:set-payload>
</dw:transform-message>
</code>```

Body:
is there a way to map a http response which is in json array to another json map also considering default values i.e when it is empty map a default key pair?

input

{

"key1": []
"key2":[x,y]
}

req output

{"table":[{
  "a-key1": "deafault-value",
  "a-key2": "x",
  "b-key2": "y"
  }]
}


问:
Use specific user in SSPI connection String in VB.net
I am making a windows form application(desktop application) that connects to database. I also created a service account domain\user. Now, i deploy my application using clickonce and use IIS to launch my application. In IIS, I set my application pool identity to the service account I created so that my application will connect to database using that service account since that was the only account with access to my database. When I test my application, it failed to connect to my database. It says that user has no connection to database. Upon checking the error, it shows that it used the account of the currently logon user in the pc where my application is launch instead of the account I set in IIS. By the way, I am using SSPI connection string, and my SQL is set to windows authentication. Is it possible for my application to use the account set in IIS to connect to my database? If no, is there a way for me to use the service account I created to connect to my database? Please help, </p>

答: here, when i click browse in IIS manager, this will load and when I click lauch, my windows form will load.

ContentLicense: CC BY-SA 4.0


问:
how to make ebs volume usable by docker stack
I'm building a multi-tier env in AWS using ansible and Docker (running in Swarm). I have one master and 2 worker nodes. I'm using Docker stack to create services in the swarm using the following command:

```<code>docker stack deploy -c myStack.yml myTest
</code>```

I have 2 questions:

my first question is all my nodes keeps running out of space because Docker is using only ec2's root volume. How can I instruct Docker to create services in EBS volume instead?

is it possible to only create services in workers nodes only and not create any services in manager? can I use the swarm manager for managing the nodes only?

Thanks in advance

答:
Let's start with your second questions, since it is easier.

You can add label to your nodes, and then use constraint when you create your service (stack is the same). e.g

```<code>docker node update --label-add "role=worker" .... # on all your worker nodes
docker service create --constraint "node.labels.role==worker" ...
</code>```

For your first question, you need data persistent. There are some solutions.

Flocker is a large solution. It has more support, more options and more secure. It is also much difficult to configure.

Blocker is the one I current using. It have to be install on every node, and I can confirm it is working and working very well. Syntax is like,

```<code>docker service create --mount type=volume,target=/data,source=vol-08a1211f22864700c,volume-driver=blocker ....
</code>```

I hope this is enough info for you to start your research.

Body:
I'm building a multi-tier env in AWS using ansible and Docker (running in Swarm). I have one master and 2 worker nodes. I'm using Docker stack to create services in the swarm using the following command:

docker stack deploy -c myStack.yml myTest

I have 2 questions:

my first question is all my nodes keeps running out of space because Docker is using only ec2's root volume. How can I instruct Docker to create services in EBS volume instead?

is it possible to only create services in workers nodes only and not create any services in manager? can I use the swarm manager for managing the nodes only?

Thanks in advance

Body:
Let's start with your second questions, since it is easier.

You can add label to your nodes, and then use constraint when you create your service (stack is the same). e.g

docker node update --label-add "role=worker" .... # on all your worker nodes
docker service create --constraint "node.labels.role==worker" ...

For your first question, you need data persistent. There are some solutions.

Flocker is a large solution. It has more support, more options and more secure. It is also much difficult to configure.

Blocker is the one I current using. It have to be install on every node, and I can confirm it is working and working very well. Syntax is like,

docker service create --mount type=volume,target=/data,source=vol-08a1211f22864700c,volume-driver=blocker ....

I hope this is enough info for you to start your research.


问:
How to include a pdf link in react.js
i want to be able to open in a new tab a PDF i have in my include folder. I'am using the create-react-app and set the link to open a new tab with the pdf, in my local it works but when i build it the tab loads as an empty page with a HTTP ERROR 404.

in my react component here is how i had it set up

```<code><NavLink to={PDF} target='_blank' className='nav-link'>pdf</NavLink>
</code>```

like i mentioned before in my local it works perfect but in my build it opens a 404 page.

答:
like i mentioned before in my local it works perfect but in my build it opens a 404 page.

This is a server error.

Find out whats wrong

Log the URL

Check the browser console for failed web requests

Fix

Once you have the URL check why there isn't a file at that URL.

Title: How to include a pdf link in react.js

Body:
i want to be able to open in a new tab a PDF i have in my include folder. I'am using the create-react-app and set the link to open a new tab with the pdf, in my local it works but when i build it the tab loads as an empty page with a HTTP ERROR 404.

in my react component here is how i had it set up

<NavLink to={PDF} target='_blank' className='nav-link'>pdf</NavLink>

like i mentioned before in my local it works perfect but in my build it opens a 404 page.


问:
How stop containers run with `docker-compose run`
I'm trying to use docker-compose to orchestrate several containers. To troubleshoot, I frequently end up running bash from within a container by doing:

```<code>$ docker-compose run --rm run web bash
</code>```

I always try pass the --rm switch so that these containers are removed when I exit the bash session. Sometimes though, they remain, and I see them at the output of docker-compose ps.

```<code>           Name                          Command                State      Ports
----------------------------------------------------------------------------------
project_nginx_1            /usr/sbin/nginx                  Exit 0
project_nginx_run_1        bash                             Up         80/tcp
project_web_1              python manage.py runserver ...   Exit 128
project_web_run_1          bash                             Up         8000/tcp
</code>```

At this point, I am trying to stop and remove these components manually, but I can not manage to do this. I tried:

```<code>$ docker-compose stop project_nginx_run_1
No such service: project_nginx_run_1
</code>```

I also tried the other commands rm, kill, etc..

What should I do to get rid of these containers?

Edit:

Fixed the output of docker-compose ps.

答:
```<code>docker-compose down
</code>```

from within the directory where it was launched, is the only way I managed to confirm it was stopped, as in docker-compose ps no longer yields it!

Body:
I'm trying to use docker-compose to orchestrate several containers. To troubleshoot, I frequently end up running bash from within a container by doing:

$ docker-compose run --rm run web bash

I always try pass the --rm switch so that these containers are removed when I exit the bash session. Sometimes though, they remain, and I see them at the output of docker-compose ps.

           Name                          Command                State      Ports
----------------------------------------------------------------------------------
project_nginx_1            /usr/sbin/nginx                  Exit 0
project_nginx_run_1        bash                             Up         80/tcp
project_web_1              python manage.py runserver ...   Exit 128
project_web_run_1          bash                             Up         8000/tcp

At this point, I am trying to stop and remove these components manually, but I can not manage to do this. I tried:

$ docker-compose stop project_nginx_run_1
No such service: project_nginx_run_1

I also tried the other commands rm, kill, etc..

What should I do to get rid of these containers?

Edit:

Fixed the output of docker-compose ps.

Body:
docker-compose down

from within the directory where it was launched, is the only way I managed to confirm it was stopped, as in docker-compose ps no longer yields it!


问:
C# Inheritance: How to invoke the base class constructor when i call the derived class constructor
I am trying to figure out how to invoke a base class constructor when I call the derived class constructor.

I have a class called "AdditionalAttachment" which is inherited from System.Net.Mail.Attachment.I have added 2 more properties to my new class so that i can have all the properties of existing Attachment class with my new properties

```<code>public class AdditionalAttachment: Attachment
{
   [DataMember]
   public string AttachmentURL
   {
       set;
       get;
   }
   [DataMember]
   public string DisplayName
   {
       set;
       get;
   }
}
</code>```

Earlier i used to create constructor like

//objMs is a MemoryStream object

```<code>Attachment objAttachment = new Attachment(objMs, "somename.pdf")
</code>```

I am wondering how can I create the same kind of constructor to my class which will do the same thing as of the above constructor of the base class

答:
Use this function:</p>

```<code>public AdditionalAttachment(MemoryStream ms, string name, etc...)
       : base(ms, name)
{
}
</code>```

Body:
I am trying to figure out how to invoke a base class constructor when I call the derived class constructor.

I have a class called "AdditionalAttachment" which is inherited from System.Net.Mail.Attachment.I have added 2 more properties to my new class so that i can have all the properties of existing Attachment class with my new properties

public class AdditionalAttachment: Attachment
{
   [DataMember]
   public string AttachmentURL
   {
       set;
       get;
   }
   [DataMember]
   public string DisplayName
   {
       set;
       get;
   }
}

Earlier i used to create constructor like

//objMs is a MemoryStream object

Attachment objAttachment = new Attachment(objMs, "somename.pdf")

I am wondering how can I create the same kind of constructor to my class which will do the same thing as of the above constructor of the base class

Body:
Use this function:

public AdditionalAttachment(MemoryStream ms, string name, etc...)
       : base(ms, name)
{
}


问:
Google Groups to Salesforce
(G-Suite Forums asked me to post here since this was more of an API question)

Here's what I am trying to accomplish (as a G-Suite Admin):

I manage a number of Google "Groups"
I am sick and tired of manually adding/deleting people to these Groups (sometimes I call them old school "Email Distribution Lists;" regardless.

Now that our Salesforce is working wonderfully - I would like to automate the addition/deletion of contacts inside Groups by creating them in Salesforce and based on some fancy Salesforce wizardry (leave that to me) - have Salesforce, via Zapier zaps, pop into G-Suite Admin and "manage" my Groups membership.

This sounds great on paper, but this is seemingly not how it works.

So, my next idea...
I give Salesofrce/Zapier access to one of my Google Mailboxes (let's call it Salesforce.Integration Mailbox) and...
that mailbox somehow has perfect dynamic, real-time copies of each of my Groups inside its CONTACTS area.

Can THAT be done?

Any help/advice is appreciated.

: )

答:
You can do this in the Enterprise Edition of Salesforce using Apex and the G Suite API.  Using Apex, you can call the G Suite API and create/update Groups and their Membership.  This can be triggered based on changes to data in Salesforce, like a field on the Contact or something.
An experienced Salesforce developer should be able to do this in 24 hours of work. G Suite API</p>

Title: Google Groups to Salesforce


问:
Running python on Sage keeps getting stuck - not showing image
I'm trying to run sage in python mode. (The reason I don't run Jupyter is that it doesn't run on my machine - I don't know why. see question).
But it keeps getting stuck all the time.
For example, I try to run this code:

```<code>img_1=np.random.poisson(lam=300,size=(1024,1024))
img_1=img_1-img_1.mean()
plt.figure(figsize=(6,6))
plt.imshow(img_1)
plt.title("wowo")
plt.show()
</code>```

But the image is not showing.

答:
Just add

```<code>plt.savefig('')
</code>```

and it should show fine.  Sage notebook needs the figure to be saved in a local directory for the cell, and this is one way to accomplish that.

Body:
I'm trying to run sage in python mode. (The reason I don't run Jupyter is that it doesn't run on my machine - I don't know why. see question).
But it keeps getting stuck all the time.
For example, I try to run this code:

img_1=np.random.poisson(lam=300,size=(1024,1024))
img_1=img_1-img_1.mean()
plt.figure(figsize=(6,6))
plt.imshow(img_1)
plt.title("wowo")
plt.show()

But the image is not showing.

Body:
Just add

plt.savefig('')

and it should show fine.  Sage notebook needs the figure to be saved in a local directory for the cell, and this is one way to accomplish that.


问:
HTML Input-Attribute "required" only for one button
I've got an file-input which is submitted with a submit button. But theres also a delete button in the same form. So my problem is, when i press the delete button it will say "Please select an file" because the "required" attribute is in the file-input. I want that this message only displays when you press the upload button(of course only if the input is empty).

Here's my Code :

```<code><form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete">
</form>
</code>```

答:
(function ($) {

    $('#my-form').validate({
        rules: {},
        messages: {},
        submitHandler: function () {
            return false
        }
    });
    $('#del_image').click(function(){

  $("#file").val("");
 });

})(jQuery);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>

<form id="my-form">
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">

<button id="del_image">Delete</button>
</form></code>```

Body:
I've got an file-input which is submitted with a submit button. But theres also a delete button in the same form. So my problem is, when i press the delete button it will say "Please select an file" because the "required" attribute is in the file-input. I want that this message only displays when you press the upload button(of course only if the input is empty).

Here's my Code :

<form>
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">
<input type="submit" name="del_image" value="Delete">
</form>

Body:
(function ($) {

    $('#my-form').validate({
        rules: {},
        messages: {},
        submitHandler: function () {
            return false
        }
    });
    $('#del_image').click(function(){

  $("#file").val("");
 });

})(jQuery);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>

<form id="my-form">
<input name="file" id="file" type="file" required>
<input type="submit" name="sub_image" value="Upload">

<button id="del_image">Delete</button>
</form>


问:
Use FCM groups for A/B Testing
I am creating a solution that permit other app editor to sent notifications to their app through Firebase Cloud Messaging, and I want to develop the possibility to do A/B Testing.
I came across the groups syteme of FCM and, if that works, it would be a good way to separate audiences in two or three groups, as it is possible to register several devices at the same time in a group. However it seems to be designed to represent the devices of a single user, which means a small number of devices.
So my question is, can we still use FCM grouping with a large number of devices (in the tens of thousands) ? Or can they not be used this way?</p>

答:
No. Device Groups have a limit of 20 tokens per group:

The maximum number of members allowed for a notification key is 20.

High volume tokens in a group could be handled by Topics better.

Title: Use FCM groups for A/B Testing