samedi 2 janvier 2016

Is it possible to redirect the python output to web by using 'sys.stdout' command?

Is it possible to redirect the python output to web by using the redirecting command? I know that we can redirect the output like this

import sys
sys.stdout = open('file', 'w')
print 'test'

or

In terminal like this

$ python foo.py > file

I heard the 'Django' and 'Flask' like web framework can do the trick. I wonder whether by using a simple command like sys.stdout can redirect the output to web?




Django: how to add http header to responses in a convenient way?

I know we can use HttpResponseInstance['headername'] = 'headervalue' to add header to http response. But in this way, I have to rewrite all the generic view I am using, which makes much more work.

Is there a convenient way to add header to responses, like a callback for responses, or a url decorator?




vendredi 1 janvier 2016

No mapping found for HTTP request with URI [/hello] in DispatcherServlet with name 'mvc-dispatcher'

Project Structure enter image description here

web.xml

<web-app version="2.5"
         xmlns="http://ift.tt/nSRXKP"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/nSRXKP
    http://ift.tt/LU8AHS">

    <display-name>Spring MVC Application</display-name>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

mvc-dispatcher-servlet.xml

<beans xmlns="http://ift.tt/GArMu6"
       xmlns:xsi="http://ift.tt/ra1lAU"
       xmlns:context="http://ift.tt/GArMu7"
       xmlns:aop="http://ift.tt/OpNdV1" xmlns:mvc="http://ift.tt/1bHqwjR"
       xsi:schemaLocation="http://ift.tt/GArMu6
        http://ift.tt/1jdM0fG
        http://ift.tt/GArMu7 http://ift.tt/1jdLYo7 http://ift.tt/OpNdV1 http://ift.tt/1feTlrW http://ift.tt/1bHqwjR http://ift.tt/1fmimld">

    <mvc:annotation-driven/>
    <mvc:default-servlet-handler/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"/>
        <property name="suffix" value=".jsp"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    </bean>

</beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
        xmlns="http://ift.tt/GArMu6"
        xmlns:xsi="http://ift.tt/ra1lAU"
        xmlns:tx="http://ift.tt/OGfeU2"
        xmlns:context="http://ift.tt/GArMu7"
        xmlns:mvc="http://ift.tt/1bHqwjR"
        xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/OGfeU2
http://ift.tt/1cQrvTl http://ift.tt/GArMu7 http://ift.tt/1jdLYo7 http://ift.tt/1bHqwjR http://ift.tt/1fmimld">

    <context:annotation-config />
    <context:component-scan base-package="sse.jason"/>

    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/library?useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <property name="initialSize" value="1"/>
        <property name="minIdle" value="1"/>
        <property name="maxIdle" value="30"/>
        <property name="maxActive" value="60"/>
        <property name="testOnBorrow" value="true" />
        <property name="testOnReturn" value="true" />
        <property name="testWhileIdle" value="true" />
    </bean>

    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <value>sse.jason.model</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
                hibernate.hbm2ddl.auto=update
                hibernate.show_sql=false
                hibernate.format_sql=false
            </value>
        </property>
    </bean>
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <tx:annotation-driven transaction-manager="txManager"/>
</beans>

HelloContoller.java

@Controller
public class HelloController {
    @RequestMapping("/")
    public String printWelcome(ModelMap model) {
       model.addAttribute("message", "Hello world!");
       return "hello";
    }

}

LoginController.java

@Controller
public class LoginController {

    @Autowired
    @Qualifier("iUserService")
    private UserService iUserService;

    @RequestMapping("/log")
    public String loginPage() {
        return "login";
    }

    @RequestMapping("/loginCheck")
    public ModelAndView login(HttpServletRequest request,LoginCommand command) {
        User user = iUserService.login(command.getUsername(),command.getPassword());
        if (user==null) {
            return new ModelAndView("error");
        } else {
            user.setLastIp(request.getRemoteAddr());
            user.setLasVisit(new Date());
            request.getSession().setAttribute("user",user);
            return new ModelAndView("index");
        }
        //return new ModelAndView("index");
    }

}

Compile results

Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Root mapping to handler 'helloController'
Jan 02, 2016 12:15:38  org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/log] onto handler 'loginController'
Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/log.*] onto handler 'loginController'
Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/log/] onto handler 'loginController'
Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/loginCheck] onto handler 'loginController'
Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/loginCheck.*] onto handler 'loginController'
Jan 02, 2016 12:15:38 org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
Info: Mapped URL path [/loginCheck/] onto handler 'loginController'

Errors

localhost:8080  404 error

warnings: No mapping found for HTTP request with URI [/hello] in DispatcherServlet with name 'mvc-dispatcher'
Jan 02, 2016 12:15:40  org.springframework.web.servlet.PageNotFound noHandlerFound

localhost:8080/log  no response

Would somebody can give me kind help? Thanks a lot.




Need some project reference code for web app using hibernate,spring,web services ,ui technologies

Can anybody please provide some link to provide implementation of little complex project made in Spring,hibernate ,rest and some UI technology ? Relational mapping should be shown clearly from end to end .. Thanks in advance




Polymer Dom Insertion Issues

I am using Polymer 1.0, and I'm having a problem retrieving and inserting into the dom and showing. I can get the HTML "li" to print to the console, but I am unable to get polymer to render the HTML.

<example-app appjs="appJsFile.js">
<ul id="content">
//I want Content Here from Polymer
</ul>
</example-app>

appJsFile.js gets imported into "example-app". I have a function for this:

    for(var i in this.listData){
        var _ele = parent.document.createElement('li');
            _ele.innerHTML = this.listData[i].listDataName;
        return _ele;
    }

Any ideas?




Gmail.com startup delay every time

Why is it acceptable for Gmail to have that loading delay of almost 6 seconds everytime that you load gmail.com on a dekstop?

Yahoo or Outlook doesn't have this problem at all.

image




FRONTEND DEVELOPMENT [on hold]

i'm looking to become a frontend developer and a good one, but i keep going back and forth with the steps to take and how to achieve this. i'm just in need of a kind of mentor that is really rooted in frontend development thta can help me along the way