|
I have an existing Spring MVC maven project. Everything in the current project is exactly what I need as a template for a new Spring project. Is there any way I can use the existing project as a template and rename it to a new project without changing anything but the name. I tried to recreate the existing project from scratch and just add the same existing components but am running into a lot of problems with the dependencies and other jar files as well as configurations.
|
|
|
|
|
I got it. All I did was select copy from the file menu and then it allowed me to rename it.
|
|
|
|
|
I need to add multiple controllers to my Spring MVC project which only has one right now. My current project only has one SpringDispatcher in the web.xml and it maps the <url-pattern>/</url-pattern> to the '/' of the controller's @RequestMapping(value = "/") controller request mapping. Because everything is in the web.xml and there are no other xml files that do any dispatcher mapping, should I not be able to just add a new <url-pattern>/</url-pattern> with a different controller pattern to the web.xml? Below are the web.xml and the one working controller.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SpringMvcJdbcTemplate</display-name>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>net.codejava.spring</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
HomeController.java
package net.codejava.spring.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.codejava.spring.dao.ContactDAO;
import net.codejava.spring.dao.ContactDAODS;
import net.codejava.spring.model.Contact;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
* This controller routes accesses to the application to the appropriate
* hanlder methods.
* @author www.codejava.net
*
*/
@Controller
public class HomeController {
@Autowired
private ContactDAO contactDAO;
@Autowired
private ContactDAODS contactDAODS;
@RequestMapping(value = "/")
public ModelAndView login() {
Contact contact = new Contact();
ModelAndView model = new ModelAndView("login");
model.addObject("contact", contact);
return model;
}
@RequestMapping(value = "/loginContact", method = RequestMethod.POST)
public ModelAndView loginContact(@ModelAttribute Contact loginContact) {
ModelAndView model;
Contact contact = contactDAO.login(loginContact);
if(contact != null)
{
model = new ModelAndView("menu");
return model;
}
else
{
Map<String, String> message = new HashMap<String, String>();
message.put("message", "Login password error");
//Message message = new Message();
//message.MessageText = "Login Error";
model = new ModelAndView("loginError");
model.addObject("message", message);
return model;
}
}
@RequestMapping(value = "/menuContact", method = RequestMethod.GET)
public ModelAndView menu(ModelAndView model){
model.setViewName("menu");
return model;
}
@RequestMapping(value = "/listContact", method = RequestMethod.GET)
public ModelAndView listContact(ModelAndView model) throws IOException{
List<Contact> listContact = contactDAO.list();
model.addObject("listContact", listContact);
model.setViewName("home");
return model;
}
@RequestMapping(value = "/newContact", method = RequestMethod.GET)
public ModelAndView newContact(ModelAndView model) {
Contact newContact = new Contact();
model.addObject("contact", newContact);
model.setViewName("ContactForm");
return model;
}
@RequestMapping(value = "/saveContact", method = RequestMethod.POST)
public ModelAndView saveContact(@ModelAttribute Contact contact) {
contactDAO.saveOrUpdate(contact);
return new ModelAndView("redirect:/");
}
@RequestMapping(value = "/deleteContact", method = RequestMethod.GET)
public ModelAndView deleteContact(HttpServletRequest request) {
int contactId = Integer.parseInt(request.getParameter("id"));
contactDAO.delete(contactId);
return new ModelAndView("redirect:/");
}
@RequestMapping(value = "/editContact", method = RequestMethod.GET)
public ModelAndView editContact(HttpServletRequest request) {
int contactId = Integer.parseInt(request.getParameter("id"));
Contact contact = contactDAO.get(contactId);
ModelAndView model = new ModelAndView("ContactForm");
model.addObject("contact", contact);
return model;
}
@RequestMapping(value="/showContact")
public ModelAndView getContact(ModelAndView model) throws IOException{
Contact contact = contactDAODS.get((Integer)25);
model.addObject("contact", contact);
model.setViewName("ContactSP");
return model;
}
}
|
|
|
|
|
Provide solution with code?
|
|
|
|
|
No.
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
We are not here to provide you with "solution with code" - that is supposed to be your job as part of your grade.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
no sir i m asking how can i relate my theory examples to industry level so here many are working thats why i asked sir?
|
|
|
|
|
//hierarchial inheritance
class Polygon
{
double height;
double width;
public void set_values(double a,double b)
{
height=a;
width=b;
}
}
class Rectangle extends Polygon
{
double area()
{
return height*width;
}
}
class Triangle extends Polygon
{
double area()
{
return (height*width)/2;
}
}
class AreaClass
{
public static void main(String[] args)
{
Rectangle obj1=new Rectangle();
Triangle obj2=new Triangle();
obj1.set_values(10,10);
obj2.set_values(10,10);
//obj1.Rectangle();
//obj1.Triangle();
System.out.println("Area of rectangle is "+obj1.area());
System.out.println("Area of Triangle is "+obj2.area());
}
}
// so sir i know the concept but i m not able to get how exactly this will be applied in industry so please provide some example then i will think and try to solve that kind of problems
|
|
|
|
|
SSHASHIDHAR wrote: how exactly this will be applied in industry Impossible to say, since the code without detailed explanation does not mean a lot. What problem is it supposed to solve?
|
|
|
|
|
Sir actually i have taken that as one simple inheritance program so i can write such theoretical programs but i wanted to know how in industry that inheritance is helpful i mean if u give some clarity then i can able to solve.
|
|
|
|
|
SSHASHIDHAR wrote: if u give some clarity then i can able to solve. Solve what? You have not defined a problem. As far as using your code in "industrial level" situations, it may well be useful, but you need to find the problem first, before you can apply the code to it.
|
|
|
|
|
I have an existing MVC application that uses the following Dispatcher:
<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
What I did was under the WEB-INF/views directory add a menu.jsp file to be the new startup jsp.
/SpringMvcJdbcTemplate/WEB-INF/views/menu.jsp
New menu.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h1>Main Menu</h1>
<h3><a href="listContact">List Contacts</a></h3>
</div>
</body>
</html>
Now what I did is change the initial "/" RequestMapping controller method to look like the following:
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView menu(ModelAndView model){
model.setViewName("menu");
return model;
}
Now I feel that everything should work but when I run the application I receive the following page errors:
HTTP Status 404 - /SpringMvcJdbcTemplate/WEB-INF/views/menu.jsp
type Status report
message /SpringMvcJdbcTemplate/WEB-INF/views/menu.jsp
description The requested resource is not available
I am not sure what I am doing wrong. Can anyone help?
|
|
|
|
|
I was doing something dumb. I misspelled "menu" as "meun". Renamed and now all is better.
|
|
|
|
|
<b>Code Design for turn based game:
I am raising this question to know the alternatives for the implementation of turn based game like poker,
Where every player gets userturn of x seconds, when the user takes the action the turn goes to next player and this continues until some condition of money betting is met.
Currently i have one design in my mind where i am defining a run() method of thread having a while loop which keeps on checking the state of the game and keeps passing the userturn until the all states show up and game ends.
I am looking for any alternative of this design, if possible.
Psuedo code goes here
gameStates enum : Ante, Preflop,Flop, Turn, River, Show
</b>
run()
{
// implementing run method of thread class
do
{
switch(gameState)
{
case Ante:
//deduct ante and distribute holecards to players
//update money pot
//change the game state to preflop
//send user turn to a player of x seconds
break;
case Preflop:
if(allPlayersBetMatch())
//distribute community cards
//change the game state to flop
else
//send userturn to players
break;
case Flop:
if(allPlayersBetMatch())
//distribute community cards
//change the game state to turn
else
//send userturn to players
break;
case Turn:
if(allPlayersBetMatch())
//distribute community cards
//change the game state to river
else
//send userturn to players
break;
case River:
if(allPlayersBetMatch())
//change the game state to show
else
//send userturn to players
break;
case Show:
//process holecards of active players
//show winners
// reset all
break;
}
}
while(runStateMachine==true)
//run method ends here
}
allPlayersBetMatch()
{
//process current user action who was given the userturn.
//returns true if all players have thrown equal money into the pot,
//else case,someone has raised the bet so find active player and send userturn of x seconds and wait for his action until turn expires
}
|
|
|
|
|
I created a new Spring MVC Dynamic web project with eclipse. I created a controller class .java file and cut and pasted code from an example project into my new class. Now in the new Controller code I have import libraries in the pasted in code. For example:
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
Now, how do I go about actually add this import libraries to my project so that they will be included in the Spring MVC application? I am currently using Eclipse to develop the application.
modified 30-Oct-15 16:43pm.
|
|
|
|
|
Have you installed the jar files on your system? If so you just need to add their location in eclipse: Go to Project -> Properties ->, select "Java Build Path" and the Libraries tab, and add the details there.
|
|
|
|
|
Message Removed
modified 30-Oct-15 16:27pm.
|
|
|
|
|
Hi, Java Friends
I'm an software engineer from China(I apologize for my ugly English), I used my spare time to develop an open source framework since 2008, after 7 years, it's has been finished and the first version is pulibshed on github. Its name is "BabyFish"
Please view
https://github.com/babyfish-ct/babyfish
to know more(The framework is also uploaded to the Maven Central Repository, but demo projects and document can only be accessed from github).
Functionalites
This framework is an Object Association Management framework(Let's call it OAM), it can be split to 2 parts
(1) Java Part
(a) Event combiner: support .NET style event notification mechanism.
(b) Typed-18N: support strong type "18N" which can report the I18N errors at compilation time.
(c) X-Collection-Framework: Enhance the Java Collection Framework. The most important functionality is "Unstable Collection Elements", element/key can be
modified after it has been added into set(map) because the corresponding sets/maps will be adjusted automatically when it's changed.
(d) MA-Collection-Framework: Enhance the X-Collection-Framework to let collections support modification notification like the trigger of database. The most
important functionality is "Bubbled Event", If the modification event has been triggered by iterator of view(eg: List.subList, SortedMap.subMap), it will bubbled to
its parent view, util the original root collection triggered the event.
(e) ObjectModel4Java: ObjectModel(Both ObjectModel4Java and ObjectModel4JPA) is the most important functionality of this framework, a powerful API to create
Java model classes, it supports the smart bidirectional association between objects. When one side bidirectional association is changed, the other side will be
notified and adjusted automatically. User only need to declare some annotations and all the functionalities will be implemented by the byte-code generated dynamically
in runtime.
(2) JPA/Hibernate Part
(a) ObjectMode4JPA: Enhance ObjectModel4Java. let ObjectModel support JPA entity classes.
(i) Replace the lazy proxy and lazy collection of Hibernate to support ObjectModel with laziness management.
(ii) Support Maven plugin to change the byte-code of entity class at compilation time, programmer only need to write the simple JPA entity classes, and
complex code for the ObjectMode4JPA can be injected into entity classes automatically during compilation.
(b) BabyFish-JPA-Criteria: A smarter implementation of JPA Criteria, it supports more functionalities, and it can optimize the generated JPQL.
(c) QueryPath: A functionality learned from "ADO.NET Entity Framework", for dynamic fetch and sort, query path can be used to to fetch the lazy properties with
unlimited depath and breadth, sort query result and sort object collection associations. It can be decided by UI Layer dynamically, then dispatched to Business Logic
Layer, and finally dispatched to the Data Access Layer.
(d) DistinctLimiQuery: Enhance the Oracle Dialect of Hibernate to resolve a problem of Hibernate, In hibernate, when paging query(with firstResult/maxResults)
contains collection fetches, hibernate has to query all the data and do the paging filter in memory. This functionality can resolve this p
|
|
|
|
|
can anyone send the display message.jsp code..am using the struts .....help me
|
|
|
|
|
Sorry no, this site does not provide code to order. But if you ask a proper question then people will try to help you.
|
|
|
|
|
@Richardd MacCutchan........haiii sir this site does not allow me to download here .....please can u mail to mvmohan19@gmail.com.....its my request
|
|
|
|
|
|
Here is my CV - short version , I am not applying for a job
Wrote my first program in assembly in 1973
...
currently enjoying life as retired OF and writing code for ATmel SAM3x8E ( I do not want to advertise here the real hardware, they do not deserve that ).
I am frustrated with rudimentary ( to put it nicely) IDE I am using ( yes I use ATmel Studio too) and would like to patch it up.
It is written in Java and I have NO experience in Java because first time I was exposed to Java someone said "it does not use pointers" and the audience cheered! So I never bothered to learn Java, until now.
Hence I am looking for simple "how to do Java" book. I do not want "Java for dummies" or "click this and that and watch the screen" book with over 500 pages fat.
I studied C using K&R book and if there is such a <b>book style on Java</b> let me know.
Cheers Vaclav
|
|
|
|
|
|
Thanks Richard, looks better that K&R Ha Ha
BTW I still owe you an answer on my template problem few weeks back.
You were absolutely right, the problem was I was not looking at the rest of the parameters I have added to the original template.
It got little convoluted using both overload and several similar templates.
But it is better now, still not finished.
( I am having too much fun with too many distractions from coding, last one - I am going back to my homeland for few weeks.)
Cheeers Vaclav
|
|
|
|
|
Hi everyone,
I would be grateful if someone help me with next problem that i have in Java:
Thing that i want to do is to make client-server chat app on web. I am using RMI. I will show just important class for my problem..
Here is mu server interface:
<pre lang="java">public interface ChatServerIF extends Remote {
//void registerChatClient(ChatClientIF chatClient) throws RemoteException;
//void broadcastMessage(String message) throws RemoteException;
void registerClient(String ime, ChatClientIF chatKlijent) throws RemoteException;
void posaljiPoruku(String ime, String poruka) throws RemoteException;
void dodajWeb(String naziv, PrintWriter print) throws RemoteException;
void pronadjiWeb(String naziv) throws RemoteException;
}
server class:
public class ChatServer extends UnicastRemoteObject implements ChatServerIF {
public static final long serialVersionUID = 1L;
private HashMap<String, ChatClientIF> hmap = new HashMap<String, ChatClientIF>();
private Map<String, PrintWriter> web = new HashMap<String, PrintWriter>();
public List<HttpServletResponse> lista = new ArrayList<HttpServletResponse>();
public ChatServer() throws RemoteException{
}
@Override
public synchronized void dodajWeb(String naziv, PrintWriter print) throws RemoteException{
web.put(naziv, print);
}
@Override
public void pronadjiWeb(String naziv) throws RemoteException {
}
and part of servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet IgraServlet</title>");
out.println("</head>");
out.println("<body>");
String username = request.getParameter("username");
ChatServerIF chat = (ChatServerIF) request.getSession().getAttribute("server");
ChatClient cc = (ChatClient) request.getSession().getAttribute("klijent");
PrintWriter pw = (PrintWriter) request.getSession().getAttribute("out");
chat.dodajWeb(username, pw);
cc.run();
out.println("aaa");
out.println("<h1>Servlet IgraServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
My idea is to store user and PrintWritter for that user, from web page on server in order i can later sent message to that client.
Am i thinking good, or completely wrong?
But problem comes when i call chatServer interface method on servlet "chat.dodajWeb(username, pw)" i got next error:
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: java.io.PrintWriter
Please help me i try to search solution on internet, but for now without result..
|
|
|
|
|