|
|
A B C
A B C
A B C
This is my output.....
Please can you write the code for java.....
But one condition, only one inner and outer for loop is exist..
|
|
|
|
|
Sounds like homework.
Also sounds like you don't need for loops.
Ultimately it sounds like you're going to fail class...
|
|
|
|
|
System.out.println("A B C");
System.out.println("A B C");
System.out.println("A B C");
|
|
|
|
|
Hi ..
I am new to Java.. I will be getting image Byte array via CORBA.. In the Java Applet I should get the image data and write on to disk in Jpg format. I am trying with below code. but ImageIO.read() fails, no clue why? Could you please advise
I AccessController.doPrivileged(new PrivilegedAction() to make to that I has write access and tested writing text file, file is getting created.
But the issue was image is not getting created from byte array
Pleaes help
I just want to create image of any format from m_imgData[] and save it to disk. Thanks in advance !!
InputStream bteArrayInputStream = new ByteArrayInputStream(m_imgData);
final BufferedImage bufferedImage = ImageIO.read(bteArrayInputStream);
ImageIO.write(bufferedImage, "jpg", new File("c:\\temp\\myImg.jpg"));
|
|
|
|
|
Check the status of the read from the stream to see why it fails. I don't think anyone here would be able to guess.
|
|
|
|
|
|
http://localhost:8014/rp/WEB-INF/classes/rp/tr.java[^]
HTTP Status 404 - /rp/WEB-INF/classes/rp/tr.java
type Status report
message /rp/WEB-INF/classes/rp/tr.java
description The requested resource is not available.
--------------------------------------------------------------------------------
Apache Tomcat/8.0.28
|
|
|
|
|
How can anyone here access a link that goes to 'localhost'? Please edit your question and explain exactly what your problem is.
|
|
|
|
|
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.
|
|
|
|