struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hicks, James" <>
Subject RE: Cannot retrieve mapping for action /j_security_check
Date Fri, 24 Aug 2001 22:01:14 GMT
If you are using container-managed authentication, why use a Struts
FormBean?  You can get the username from the container using the
getCallPrincipal() method of HttpServletRequest to get the logged in user's

If you absolutely want to use an ActionForm via Struts, keep reading.

You will need to create a FormBean with 2 fields of type String.
-- Code for --
package com.yourcompany.yourapp.LoginForm;

//import statements here

public class LoginForm extends ActionForm {
    protected String j_username;
    protected String j_password;

    public LoginForm() {

    public void setJ_username(String j_username) {
        this.j_username = j_username;

    public String getJ_username() {
        return j_username;

    public void setJ_password(String j_password) {
        this.j_password = j_password;

    public String getJ_password() {
        return j_password;

    //other methods for ActionForm
-- End Code -- 

You will also have to supply the name and type parameters in the <html:form>
-- code for login.jsp --
<html:form name="loginForm" 
<%-- Other html elements --%>
-- end code --

You will also need to declare your LoginForm inside struts-config.xml

-- code for struts-config.xml --
    <form-bean name="loginForm" type="com.yourcompany.yourapp.LoginForm"/>
    <!-- other form-bean declarations -->
  <!-- other struts-config elements -->
-- end code --

That should be it, just make sure you setup your web.xml file to use
form-based login.

James Hicks

-----Original Message-----
From: Shriver, Ryan [] 
Sent: Friday, August 24, 2001 2:50 PM
To: 'Jay Patel '; ''' '
Subject: RE: Cannot retrieve mapping for action /j_security_check

 Thanks for the quick reply but this seems like too much work just to get
some consistency across my .jsp forms. I would think there would be a way
for struts to let forms posted to j_security_check pass through to the
servlet container instead of the normal Action classes. I want the
container, not Struts, to do my authentication/authorization.

Thanks for the help though.


-----Original Message-----
From: Jay Patel
To: ''
Sent: 8/24/2001 3:41 PM
Subject: RE: Cannot retrieve mapping for action /j_security_check

You will need to add the Action mapping in your struts-config.xml file.
will also need the form-bean mapping that your form will use to pass the
form data to the action class.

Here is an example.

    <!-- Loin form bean -->
    <form-bean      name="loginForm"

    <!-- Process a user login -->
    <action    path="/login"
       <forward name="success"              path="/home.jsp"/>

All in all you will need the following:

1. A form bean to carry the data
2. Action servlet to perform your action
3. Form bean declaration in struts-config
4. Action mapping in struts-config

Good luck.

Jay Patel
972-849-0373 Mobile

-----Original Message-----
From: Shriver, Ryan [] 
Sent: Friday, August 24, 2001 2:26 PM
To: ''
Subject: Cannot retrieve mapping for action /j_security_check

Hello all,
I looked in the archives but couldn't find an answer to my question. I'd
like to convert my working form-based login page to use struts' html
taglib. I get the following Exception when trying to load login.jsp:

javax.servlet.ServletException: Cannot retrieve mapping for action

I was hoping someone could help out with the conversion. This works:

<form name="login" action="j_security_check" method="POST">
  <table border="3" cellpadding="2" cellspacing="2" align="center">
    <th align="right">Username:</th>
    <td><input type="text" name="j_username" size="20"></td>
    <th align="right">Password:</th>
    <td><input type="password" name="j_password" size="20"></td>
  <tr align="center">
    <td colspan="2"><input type="submit" value="Login"></td>

This does not:

<html:form action="j_security_check" focus="j_username">
  <table border="3" cellpadding="2" cellspacing="2" align="center">
    <th align="right">Username:</th>
    <td><html:text property="j_username"/></td>
    <th align="right">Password:</th>
    <td><html:password property="j_password"/></td>
  <tr align="center">
    <td colspan="2"><html:submit>Login</html:submit></td>

I'm hoping all I need to do is add an entry in struts-config.xml, but
not sure what that entry should be. Any help would be appreciated.


View raw message