• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

controller cannot be mappped

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have built a small login application using spring mvc. but there is some error coming (HTTP Status 404 - /Myspringapp11/login).
I have used Multiactioncontroller with simpleurlhandlermapping.

Here goes the code:

web.xml file
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/myServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>*.*</url-pattern>
</servlet-mapping>
----------------------------------------------------------------------------


myServlet-servlet.xml

<beans>

<bean id="commonResolver" class="org.springframework.web.servlet.mvc.multiac tion.ParameterMethodNameResolver">
<property name="paramName">
<value>method</value>
</property>
</bean>

<bean id="loginController" class="beans.LoginController">
<property name="methodNameResolver"><ref bean="commonResolver"/></property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="login">loginController</prop> <!-- there should be bean defined with the name of loginController -->
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="prefix"><value>/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>

</beans>
--------------------------------------------------------------------------
login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="javascript">

function submitForm(formName,action)

{

obj = eval('document.'+formName);

obj.action = action;
obj.submit();
}

</script>
</head>
<body>

<h3>
Please login to enter
</h3>
<form name="form1" method="post" action="">

Username:
<input type="text" name="user" />
<br><br>
Password:
<input type="password" name="pass" />
<br><br>

<input type="button" name="sub1" value="Login" onclick="submitForm('form1','login?method=loginhan dle')" />
<input type="button" name="sub2" value="Register" onclick="submitForm('form1','login?method=toNewUse r')" />

</form>

</body>
</html>
-----------------------------------------------------------------------


--------------------------------------------------------------------------

LoginController.java

package beans;
import javax.servlet.http.*;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController;

public class LoginController extends MultiActionController
{


protected ModelAndView loginhandle(HttpServletRequest arg0,
HttpServletResponse arg1)
{

Mydao myd=new Mydao();
Logininfo logininfo=new Logininfo();

if (myd.validate(logininfo.getUser(), logininfo.getPass()))
{
System.out.println("22222");
return new ModelAndView("home");
}

else
{
System.out.println("333333");
return new ModelAndView("failure");
}
}

protected ModelAndView toNewUser(HttpServletRequest arg0,
HttpServletResponse arg1)
{
return new ModelAndView("newuser");


}

}
--------------------------------------------------------------------------

Logininfo.java

package beans;
public class Logininfo {

private String user;
private String pass;

public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}



}
---------------------------------------------------------------------

mydao.java

package beans;

import java.sql.*;

public class Mydao {

public boolean validate(String user, String pass)
{
Boolean b1=false;
ResultSet rs;


try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb1","root","root");
PreparedStatement pst=con.prepareStatement("select * from loginuser where username=? and password=?");
pst.setString(1, user);
pst.setString(2, pass);
System.out.println("user:"+user+"pass"+pass);
rs=pst.executeQuery();


if(rs.next())
{
b1= true;
}

else
{
b1=false;
}

}
catch(Exception e)
{
System.out.println(e);
}
return b1;

}
}
--------------------------------------------------------------------------

Pleas help me. Its a very small and simple application. I am getting this error in the browser when i click on any of the 2 buttons.

HTTP Status 404 - /Myspringapp11/login

type Status report

message /Myspringapp11/login

description The requested resource (/Myspringapp11/login) is not available.

-->there is no error in the eclipse console. Why is my application not able to map the controller??? Please help....

Thanks in advance
Nilay
 
reply
    Bookmark Topic Watch Topic
  • New Topic