{"id":65,"date":"2009-12-18T20:54:29","date_gmt":"2009-12-18T19:54:29","guid":{"rendered":"http:\/\/www.pmannel.de\/wordpress\/?p=65"},"modified":"2011-01-08T17:41:55","modified_gmt":"2011-01-08T16:41:55","slug":"gaej-und-spring-teil-1","status":"publish","type":"post","link":"https:\/\/www.pmannel.de\/wordpress\/?p=65","title":{"rendered":"GAE\/J und Spring: Teil 1"},"content":{"rendered":"<p>Aufsetzen eines GAE\/J-Projekts<\/strong><\/p>\n<p>Download und Installation des Google App Engine SDK:<a href=\"http:\/\/code.google.com\/appengine\/downloads.html\"> SDK<\/a><br \/>\nAu\u00dferdem nat\u00fcrlich das Plugin f\u00fcr Eclipse: <a href=\"http:\/\/code.google.com\/appengine\/downloads.html#Download_the_Google_Plugin_for_Eclipse\">Plugin<\/a><\/p>\n<p style=\"text-align: left;\">Dann ein neues Web Application Project anlegen, dabei aber den Haken bei \u201cUse Google Web Toolkit\u201d rausnehmen<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-57 aligncenter\" title=\"Anlegen\" src=\"http:\/\/www.pmannel.de\/wordpress\/wp-content\/uploads\/crate-299x300.png\" alt=\"Anlegen\" height=\"300\" width=\"299\"><\/p>\n<p style=\"text-align: left;\">Als n\u00e4chstes die Spring Libraries hinzuf\u00fcgen:<\/p>\n<ul>\n<li>spring-core.jar<\/li>\n<li>spring-beans.jar<\/li>\n<li>spring-context.jar<\/li>\n<li>spring-web.jar<\/li>\n<li>spring-webmvc.jar<\/li>\n<li>jstl.jar<\/li>\n<li>standard.jar<\/li>\n<li>commons-logging.jar<\/li>\n<\/ul>\n<p>Auf keinen Fall die All-In-One spring.jar benutzen, da javax.naming.* von <b style=\"color: black; background-color: rgb(255, 255, 102);\">GAE<\/b> nicht unterst\u00fctzt wird.<\/p>\n<p>Spring Security lasse ich vorerst weg!<\/p>\n<p>Als n\u00e4chstes in der web.xml das Dispatcher-Servlet bekanntmachen:<\/p>\n<pre class=\"brush:xml\">\r\n<web-app xmlns=\"http:\/\/java.sun.com\/xml\/ns\/j2ee\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemalocation=\"http:\/\/java.sun.com\/xml\/ns\/j2ee\" version=\"2.4\">\r\n\r\n\t<servlet>\r\n\t\t<servlet-name>dispatcher<\/servlet-name>\r\n\t\t<servlet-class>org.springframework.web.servlet.DispatcherServlet<\/servlet-class>\r\n\t\t<load-on-startup>1<\/load-on-startup>\r\n\t<\/servlet>\r\n\r\n\t<servlet-mapping>\r\n\t\t<servlet-name>dispatcher<\/servlet-name>\r\n\t\t<url-pattern>*.html<\/url-pattern>\r\n\t<\/servlet-mapping>\r\n\r\n\t<!-- Loads the Spring-Context.xml -->\r\n<listener>\r\n<listener-class>org.springframework.web.context.ContextLoaderListener<\/listener-class>\r\n\t<\/listener>\r\n\t<context-param>\r\n<param-name>contextConfigLocation<\/param-name>\r\n<param-value>\r\n\t\t\tWEB-INF\/application-context.xml\r\n\t\t\t<\/param-value>\r\n\t<\/context-param>\r\n\r\n    <welcome-file-list>\r\n    \t<welcome-file>index.jsp<\/welcome-file>\r\n    <\/welcome-file-list>\r\n<\/web-app>\r\n<\/pre>\n<p>Achtung: Wer El\/JSTL benutzen m\u00f6chte, sollte die 2.4 Version im Schema verwenden, oder ElIgnored in der JSP auf false setzen!<\/p>\n<p>Ich habe auch schon f\u00fcr sp\u00e4ter eine application-context.xml in der web.xml angelegt!<\/p>\n<p>Eine JSP mit Formular, um sich anzumelden:<\/p>\n<pre class=\"brush:java\">\r\n<%@ page language=\"java\" contentType=\"text\/html;charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n<%@ include file=\"\/jsp\/include.jsp\"%>\r\n\r\n\r\n\r\n<form:form commandname=\"Login\" method=\"post\">\r\n<table>\r\n<tbody><tr>\r\n<td>Username<\/td>\r\n<td>\r\n<form:input path=\"j_username\"><\/form:input><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>Passwort<\/td>\r\n<td>\r\n<form:password path=\"j_password\"><\/form:password><\/td>\r\n<\/tr>\r\n<tr>\r\n<td colspan=\"2\">\r\n<input value=\"Absenden\" type=\"submit\"><\/td>\r\n<\/tr>\r\n<\/tbody><\/table>\r\n<\/form:form>\r\n\r\n<\/pre>\n<p>Der dazugeh\u00f6rende Controller:<\/p>\n<pre class=\"brush:java\">\r\npackage de.<b style=\"color: black; background-color: rgb(160, 255, 255);\">pmannel<\/b>.login;\r\n\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport org.springframework.validation.BindException;\r\nimport org.springframework.web.servlet.ModelAndView;\r\nimport org.springframework.web.servlet.mvc.SimpleFormController;\r\nimport org.springframework.web.servlet.view.RedirectView;\r\n\r\npublic class LoginController extends SimpleFormController\r\n{\r\n\r\n\t@Override\r\n\tprotected ModelAndView onSubmit(HttpServletRequest request,\r\n\t\t\tHttpServletResponse response, Object command, BindException errors)\r\n\t\t\tthrows Exception\r\n\t{\r\n\t\tModelAndView mv = new ModelAndView(new RedirectView(getSuccessView()));\r\n\r\n\t\tUser user = (User)command;\r\n\t\tmv.addObject(\"username\",user.getJ_username());\r\n\t\treturn mv;\r\n\t}\r\n}\r\n<\/pre>\n<p>Die Jsp, an die gepostet wird:<\/p>\n<pre class=\"brush:java\">\r\n<%@ page language=\"java\" contentType=\"text\/html;charset=UTF-8\" pageEncoding=\"UTF-8\"%>\r\n<%@ include file=\"\/jsp\/include.jsp\"%>\r\n\r\nhi <c:out value=\"${username}\">!\r\n<\/c:out>\r\n<\/pre>\n<p>Der Controller daf\u00fcr:<\/p>\n<pre class=\"brush:java\">\r\npackage de.<b style=\"color: black; background-color: rgb(160, 255, 255);\">pmannel<\/b>.login;\r\n\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport org.springframework.web.bind.ServletRequestUtils;\r\nimport org.springframework.web.servlet.ModelAndView;\r\nimport org.springframework.web.servlet.mvc.Controller;\r\n\r\npublic class MyAppController implements Controller\r\n{\r\n\r\n\t@Override\r\n\tpublic ModelAndView handleRequest(HttpServletRequest arg0,\r\n\t\t\tHttpServletResponse arg1) throws Exception\r\n\t{\r\n\t\tModelAndView mv = new ModelAndView(\"myapp\");\r\n\r\n\t\tmv.addObject(\"username\",ServletRequestUtils.getStringParameter(arg0, \"username\"));\r\n\r\n\t\treturn mv;\r\n\t}\r\n}\r\n<\/pre>\n<p>und meine Dispatcher-Servlet.xml:<\/p>\n<pre class=\"brush:xml\">\r\n<beans xmlns=\"http:\/\/www.springframework.org\/schema\/beans\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xmlns:aop=\"http:\/\/www.springframework.org\/schema\/aop\" xmlns:util=\"http:\/\/www.springframework.org\/schema\/util\" xmlns:tx=\"http:\/\/www.springframework.org\/schema\/tx\" xsi:schemalocation=\"http:\/\/www.springframework.org\/schema\/beans\r\n\r\nhttp:\/\/www.springframework.org\/schema\/beans\/spring-beans-2.0.xsd\r\n\r\nhttp:\/\/www.springframework.org\/schema\/aop\r\n\r\nhttp:\/\/www.springframework.org\/schema\/aop\/spring-aop-2.0.xsd\r\n\r\nhttp:\/\/www.springframework.org\/schema\/util\r\n\r\nhttp:\/\/www.springframework.org\/schema\/util\/spring-util-2.0.xsd\r\n\r\nhttp:\/\/www.springframework.org\/schema\/tx\r\n\r\n    http:\/\/www.springframework.org\/schema\/tx\/spring-tx-2.0.xsd\">\r\n\r\n\t<bean id=\"defaultHandlerMapping\" class=\"org.springframework.web.servlet.handler.SimpleUrlHandlerMapping\">\r\n<property name=\"order\" value=\"0\">\r\n<property name=\"alwaysUseFullPath\" value=\"true\">\r\n<property name=\"mappings\">\r\n<props>\r\n<prop key=\"\/login.html\">loginController<\/prop>\r\n<prop key=\"\/secure\/myapp.html\">myAppController<\/prop>\r\n\t\t<\/props>\r\n\t\t<\/property>\r\n\t<\/property>\r\n\r\n\t<bean id=\"loginController\" class=\"de.pmannel.login.LoginController\">\r\n<property name=\"commandClass\" value=\"de.pmannel.login.User\">\r\n<property name=\"commandName\" value=\"Login\">\r\n<property name=\"formView\" value=\"login\">\r\n<property name=\"successView\" value=\"secure\/myapp.html\">\r\n\t<\/property>\r\n\r\n\t<bean id=\"myAppController\" class=\"de.pmannel.login.MyAppController\"><\/bean>\r\n\r\n\t<bean id=\"viewResolver\" class=\"org.springframework.web.servlet.view.InternalResourceViewResolver\">\r\n<property name=\"prefix\" value=\"\/jsp\/\">\r\n<property name=\"suffix\" value=\".jsp\">\r\n\t<\/property>\r\n\r\n<\/property><\/bean><\/property><\/property><\/property><\/bean><\/property><\/bean><\/beans>\r\n<\/pre>\n<p>in der include.jsp kommen folgende Taglibs:<\/p>\n<pre class=\"brush:java\">\r\n<%@ taglib prefix=\"c\" \t\t\turi=\"http:\/\/java.sun.com\/jsp\/jstl\/core\" %>\r\n<%@ taglib prefix=\"fmt\" \t\turi=\"http:\/\/java.sun.com\/jsp\/jstl\/fmt\" %>\r\n<%@ taglib prefix=\"spring\" \t\turi=\"http:\/\/www.springframework.org\/tags\" %>\r\n<%@ taglib prefix=\"form\" \t\turi=\"http:\/\/www.springframework.org\/tags\/form\" %>\r\n\r\n<\/pre>\n<p>Wenn dann alles soweit fertig ist, rechte Maustaste auf das Projekt, Run As \u2013> Web Application!<\/p>\n<p>Damit l\u00e4uft GAE\/J schonmal mit Spring MVC! Als n\u00e4chstes versuche ich, mit Spring ORM und JDO den User im DataStore zu speichern.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Aufsetzen eines GAE\/J-Projekts Download und Installation des Google App Engine SDK: SDK Au\u00dferdem nat\u00fcrlich das Plugin f\u00fcr Eclipse: Plugin Dann ein neues Web Application Project anlegen, dabei aber den Haken bei \u201cUse Google Web Toolkit\u201d rausnehmen Als n\u00e4chstes die Spring Libraries hinzuf\u00fcgen: spring-core.jar spring-beans.jar spring-context.jar spring-web.jar spring-webmvc.jar jstl.jar standard.jar commons-logging.jar Auf keinen Fall die All-In-One&#8230; <\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.pmannel.de\/wordpress\/?p=65\">Weiterlesen<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10,11],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-google-app-engine","category-spring-mvc","category-spring-security"],"_links":{"self":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":4,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":135,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions\/135"}],"wp:attachment":[{"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pmannel.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}