Simple blog wall creation on Java

1,004 views

Published on

Published in: Self Improvement
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,004
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Simple blog wall creation on Java

  1. 1. Ja basva ed
  2. 2. JAVASPRING-CORESPRING SECURITYJSPMYSQLTOMCATJUNIT
  3. 3. JDK 7IDEMySQL 5Tomcat 7Maven 3
  4. 4. 1 run mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.0 -DgroupId=blog-wall -DartifactId=blog-wall -Dversion=1.0-SNAPSHOT2 configure spring core and spring security
  5. 5. -Install MySQL-Make project-Build war-Deploy
  6. 6. Development process• configs• Java classes• jsp
  7. 7. applicationContext-security.xml• <authentication-manager>• <authentication-provider>• <jdbc-user-service data-source-ref="dataSource"• users-by-username-query="• select username,password, enabled• from users where username=?"• authorities-by-username-query="• select u.username, ur.authority from users u, user_roles ur• where u.user_id = ur.user_id and u.username =? "• />• <password-encoder ref="encoder"/>• </authentication-provider>• </authentication-manager>
  8. 8. blog-wall-servlet.xml• <context:component-scan base-package="com.makstitoff.blogwall"/>• <context:annotation-config/>• <tx:annotation-driven transaction-manager="transactionManager"/>• <bean id="entityManagerFactory"• class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">• <property name="dataSource" ref="dataSource"/>• <property name="jpaVendorAdapter">• <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">• <property name="generateDdl" value="true"/>• <property name="database" value="MYSQL"/>• <property name="showSql" value="true"/>• </bean>• </property>• <property name="persistenceUnitName" value="jpa.sample"/>• </bean>
  9. 9. RegistrationController• @Controller• public class RegistrationController {• @Autowired• private UserService userService;• @RequestMapping(value = "/register", method = RequestMethod.POST)• public String createNewUser(final @RequestParam(value = "login", required = true) String login, final @RequestParam(value = "password", required = true) String password) {• userService.createNewUser(login, password);• return "redirect:/index.jsp";• }• }
  10. 10. PostController• @Controller• public class PostController {• @Autowired• private PostService postService;• @RequestMapping(value = "/getAllPosts", method = RequestMethod.POST)• public ModelAndView getAllPosts() {• List<Post> posts = postService.getAll();• return new ModelAndView("posts", "posts", posts);• }• @RequestMapping(value = "/post", method = RequestMethod.POST)• public String post(@RequestParam(value = "text", required = true) String text) {• if (text.length() > 1024) {• text = text.substring(0, 1024);• }• postService.post(text);• return "redirect:/index.jsp";• }

×